Question discussion

What is the output of the following JavaScript code?

359449Medium DSSSB TGT Computer Science 0 replies 0 views
0
What is the output of the following JavaScript code?
const obj = { name: "Alice" };
Object.defineProperty(obj, "age",
{
    value: 25,
    writable: false
});
obj.age = 30;
console.log(obj.age);
  • Aundefined
  • BError: Cannot modify property
  • C25
  • D30
Correct answer: C

Explanation

writable: false prevents the assignment, so the value stays 25 (no error is thrown outside strict mode).

Discussion 0

Nobody has replied yet. Start the discussion!