Reputation: 4594
It seems that the undefined is a property of window/global :
I always thought that undefined is, like null, a uniqe value in JavaScript.
But above code (tested in Chrome) make me confused.
Can some explain why
undefined in window
evalute to true, while
null in window
evaluate to false
Upvotes: 11
Views: 1493
Reputation: 4067
Not only undefined
, but also Infinity
and NaN
are values of the global object
, in this case, window
(as of ES5.1 specification).
The fact you can't assign a value to undefined
is because the property is defined with the writable
attribute set to false
.
null
is a primitive value
(as is 5
) of the type Null
(as is Number
for 5
), not a property of window
.
Take a look at the annotated ES5 specification for more background on this, its quite readable!
Upvotes: 13