Q
What happens if you try to reassign a constant object to a new object in JavaScript?

Answer & Solution

Answer: Option B
Solution:
Trying to reassign a constant object reference to a new object in JavaScript will result in a TypeError being thrown.
Related Questions on Average

What is the output of the following code snippet?

A). A. { a: 1, b: 2, c: 3 }

B). B. { a: 1, b: 2 }

C). C. { c: 3 }

D). D. Error

Which of the following will cause an error when used with a constant object in JavaScript?

A). A. Modifying a property using bracket notation

B). B. Adding a property using dot notation

C). C. Deleting a property

D). D. Reassigning the object reference

What happens if you use Object.freeze() on a constant object in JavaScript?

A). A. The object reference becomes mutable

B). B. The properties of the object become immutable

C). C. The object becomes frozen and cannot be modified

D). D. A TypeError is thrown

How can you prevent modifications to the properties of a JavaScript object?

A). A. Use Object.preventExtensions()

B). B. Use const for each property

C). C. Use Object.freeze() to freeze the object

D). D. All of the above

What is the output of the following code snippet?

A). A. { x: 10, y: 20 }

B). B. { x: 20, y: 10 }

C). C. { x: 10 }

D). D. Error

How can you change the properties of a constant object in JavaScript?

A). A. Use Object.freeze()

B). B. Use const for each property

C). C. Use the delete keyword to remove properties

D). D. Use dot notation or bracket notation

What happens if you try to modify a property of a frozen object in JavaScript using Object.freeze()?

A). A. The property is modified successfully

B). B. A TypeError is thrown

C). C. The property is deleted

D). D. The object becomes mutable

How can you ensure that a constant object remains unchanged in JavaScript?

A). A. Use Object.preventExtensions()

B). B. Use Object.freeze() to freeze the object

C). C. Use const for each property

D). D. All of the above

How can you check if an object is frozen in JavaScript?

A). A. Using the frozen property

B). B. Using the isFrozen() method

C). C. Using the Object.isFrozen() method

D). D. All of the above

Which of the following is a valid way to define a constant object in JavaScript?

A). A. const obj = { a: 1, b: 2 };

B). B. const obj = new Object({ a: 1, b: 2 });

C). C. Both A and B

D). D. None of the above