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

Answer & Solution

Answer: Option D
Solution:
Constant objects in JavaScript can have their properties changed using dot notation or bracket notation to access and modify the properties.
Related Questions on Average

What is the result of the expression Object.keys(person).length for the following code snippet?

A). A. 1

B). B. 2

C). C. 3

D). D. Error

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

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

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

A). A. No error, the assignment is successful

B). B. TypeError is thrown

C). C. SyntaxError is thrown

D). D. ReferenceError is thrown

Which statement about constant objects in JavaScript is correct?

A). A. Constant objects can have their properties reassigned

B). B. Constant objects cannot have properties added or removed

C). C. Constant objects are only applicable to primitive values

D). D. Constant objects are mutable

Which statement is true about constant objects in JavaScript?

A). A. The properties of a constant object cannot be changed

B). B. Constant objects are frozen and immutable

C). C. Constant objects cannot have properties added or deleted

D). D. The object reference can be reassigned

What happens if you try to delete a property from a constant object in JavaScript?

A). A. The property is deleted successfully

B). B. A TypeError is thrown

C). C. A SyntaxError is thrown

D). D. Nothing happens

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

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 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