Why doesn't `` w90> 'appear in a for ... in loop?

I am a little confused regarding for - in loops:

 window.hasOwnProperty(undefined) // Returns true 

and

 undefined in window // Returns true 

but the following does not print Undefined is in window!

 for(a in window) { if(a === 'undefined') console.log('Undefined is in window!'); } 

Why doesn't undefined appear in a for - in loop?

+4
source share
1 answer

This is not an enumerated property. In modern JavaScript machines, you control this in your own objects, but it has always been so (well, maybe not for every interpreter) that "native" objects could "hide" properties from for ... in iterations.

You can read about Object.defineProperty() in MDN . I'm not sure if the syntax (in Harmony) will mark properties as non-enumerable in object literals.

+7
source

All Articles