javascriptpropertiesattributesdescriptorwritable

Why can't I set the writable attribute using a property descriptor in Object.create()?


I am new to JS and I wonder why this piece of code prints false. What am I doing wrong? Thank you for any hint!

var x = Object.create(Object.prototype, {x:{value:3, writable:true, enumerable:true}});

console.log(x.propertyIsEnumerable(x)); //false

Solution

  • Well, you missed the quotes:

    x.propertyIsEnumerable('x')
    

    See below:

    var x = Object.create(Object.prototype, {x:{value:3, writable:true, enumerable:true}});
    
    console.log(x.propertyIsEnumerable('x'));