Why is my for loop not working on my Javascript properties?

ecmascript-5, javascript

Solution

The default value for `enumerable` in `defineProperty` is `false`; non-enumerable properties do not show up in `for…in` loops. (That's the whole point of the `enumerable` flag.) If you add `enumerable:true` into your second definition also, it will 'fix' it.

See some docs.

Problem

I created this object and it's properties: ``` var obj = {}; Object.defineProperty( obj, "value", { value: true, writable: false, enumerable: true, configurable: true }); var name = "John"; Object.defineProperty( obj, "name", { get: function(){ return name; }, set: function(value){ name = value; } }); ``` So then I call a for loop on them: ``` for ( var prop in obj ) { console.log( prop ); } ``` Which according to my tutorial, should produce the following results: ``` value name ``` But instead it only displays value. Why is name not showing up?

Original source