admin 管理员组

文章数量: 1087134

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

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

Share Improve this question edited Apr 22, 2013 at 8:23 Henrik Andersson 47.3k16 gold badges100 silver badges94 bronze badges asked Apr 22, 2013 at 7:40 aztackaztack 4,6247 gold badges35 silver badges57 bronze badges 1
  • relevant: /questions/776950/javascript-undefined-undefined – John Dvorak Commented Apr 22, 2013 at 7:44
Add a ment  | 

1 Answer 1

Reset to default 12

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!

本文标签: javascriptIs undefined a property of windowglobalStack Overflow