在Javascript中,是:
if(typeof p_options.data_type !== "undefined") { }
绝对等同于:
if(p_options.data_type) { }
是否有任何边缘案件或陷阱?
答案 0 :(得分:4)
否即可。它绝对不一样。
想象一下,如果p_options.data_type
是false
,0
,""
或任何其他"falsey"值。这与undefined
非常不同。
p_options.data_type = false;
console.log(typeof p_options.data_type !== "undefined"); // true
console.log(p_options.data_type); // false