使用 typeof 來檢測對象是否undefined
需求
判斷是否為undefined
解決
使用 typeof 來檢測對象是否已定義:
if (typeof Obj !== "undefined" && Obj !== null)
JavaScript 中, null 用于對象, undefined 用于變量,屬性和方法。
對象只有被定義才有可能為 null,否則為 undefined。
判斷是否為undefined
使用 typeof 來檢測對象是否已定義:
if (typeof Obj !== "undefined" && Obj !== null)
JavaScript 中, null 用于對象, undefined 用于變量,屬性和方法。
對象只有被定義才有可能為 null,否則為 undefined。