Question 16
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const o = {};
Object.defineProperty(o, "id", { value: 7 });
o.id = 9;
console.log(o.id, Object.keys(o), JSON.stringify(o));
- A 9 [ 'id' ] {"id":9}
- B 7 [ 'id' ] {"id":7}
- C 9 [] {}
- D 7 [] {} Correct
Correct Answer: Option D
Without explicit flags the property is non-writable (the assignment is silently ignored) and non-enumerable (hidden from keys and JSON).
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!