I just read this excellent question and top answer on "== versus ===".
var x = undefined;
When checking if x
is truly equal to undefined
, both of the below worked.
if(typeof x == "undefined") {
console.log("typeof x == \"undefined\"");
}
if(x === undefined) {
console.log("x === undefined");
}
output:
typeof x == "undefined"
x === undefined
Is one way more idiomatic than the other? If so, why?