In JavaScript, typeof {}
returns "object", while evaluating {}
returns undefined. Why is this?
var a;
a; //undefined
{}; //undefined
typeof a === typeof {}; //false
In JavaScript, typeof {}
returns "object", while evaluating {}
returns undefined. Why is this?
var a;
a; //undefined
{}; //undefined
typeof a === typeof {}; //false
That's because typeof a
is "undefined"
and typeof {}
is "object"
:
console.log(typeof a); // "undefined"
console.log(typeof {}); // "object"
Also, as @adeneo commented, {}
is not undefined
:
console.log({} == undefined); // false