What is the output of the following JavaScript code? const obj = { name: "Alice" };
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);
Show answerHide answer
Correct answer: (C) 25
Explanation
writable: false makes the age property read-only. In non-strict mode, obj.age = 30 is silently ignored, so 25 is printed. Strict mode would throw a TypeError.