Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following JavaScript code?
const obj1 = { property1: ’10’};
const obj2 = Object.freeze(obj1);
obj2.property1 = ’20’;
console.log(obj2.property1);

What will be the output of the following JavaScript code?
const obj1 = { property1: ’10’};
const obj2 = Object.freeze(obj1);
obj2.property1 = ’20’;
console.log(obj2.property1);
a) 10
b) 20
c) Runtime error
d) Compilation error

Answer: a
Explanation: The Object.freeze() method “freezes” the properties of object and prevents new properties from being added to it. This method prevents the modification of existing property, attributes, and values.

Join The Discussion