ganqqwerty / 123-Essential-JavaScript-Interview-Questions

JavaScript interview Questions
BSD 3-Clause "New" or "Revised" License
5.01k stars 1.18k forks source link

Question 49 #78

Closed givehug closed 5 years ago

givehug commented 5 years ago

Hi, thanks for the questionnaire!

A small correction:

// Create non-enumerable property
Object.defineProperty(person, 'phoneNo',{
    value : '8888888888',
    enumerable: false
})

Changing non-enumerable property value will return error in strict mode. In non-strict mode it won't through any error but it won't change the value of phoneNo.

Value of phoneNo won't change because 'writable' descriptor is false by default, not because 'enumerable' is false.

If you had:

Object.defineProperty(person, 'phoneNo',{
    value : '8888888888',
    enumerable: false,
        writable: true,
})

you would be able to change property value.

ganqqwerty commented 5 years ago

thanks for that, can you please create a PR?

givehug commented 5 years ago

thanks for that, can you please create a PR?

here you go