vintagexav
vintagexav

Reputation: 2057

JS: difference between undefined and `undefined`

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

Answers (2)

jfriend00
jfriend00

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

vintagexav
vintagexav

Reputation: 2057

According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof typeof always returns a string.

Upvotes: 2

Related Questions