JavaScript · Middle · Question 33 of 75

What does Object.defineProperty(obj, 'id', { value: 1, writable: false }) give you?

Explanation

Every property has writable, enumerable and configurable flags. With defineProperty, unspecified flags default to false, so the property won't appear in Object.keys and can't be deleted. Getters and setters are defined this way too.

Further reading

Problem with a question

JavaScript · Middle · question 33

Test yourself

Take the JavaScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz