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
The undefined property indicates that a variable has not been assigned a value, or not declared at all.
In a JavaScript program, the correct way to check if an object property is undefined is to use the typeof operator. If the value is not defined, typeof returns the 'undefined' string.
Description. undefined is a property of the global object. That is, it is a variable in global scope. The initial value of undefined is the primitive value undefined .
undefined means that the variable value has not been defined; it is not known what the value is. null means that the variable value is defined and set to null (has no value).
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With