Reputation: 2057
Looking at this code; why doesn't a satisfy (a === typeof a)
var a;
(a === undefined)?console.log("a is undefined"):null;
(typeof a === 'undefined')?console.log("typeof a is 'undefined'"):null;
Upvotes: 1
Views: 44
Reputation: 707238
Because:
var a;
typeof a === 'undefined';
a === undefined;
One is a string with the string value 'undefined'
, one is the undefined
primitive. Those two are not the same.
typeof x
always returns string values such as "undefined"
, "boolean"
, "string"
, "object"
, etc....
Upvotes: 1
Reputation: 2057
According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof typeof
always returns a string.
Upvotes: 2