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
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
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 data type of a constant object in JavaScript?
A). A. Object
B). B. Array
C). C. Function
D). D. String
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. { a: 1, b: 2, c: 3 }
B). B. { a: 1, b: 2 }
C). C. { c: 3 }
D). D. Error
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
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
Which of the following will result in an error when using a constant object in JavaScript?
A). A. Modifying an existing property
B). B. Adding a new property
C). C. Reassigning the object reference
D). D. None, all operations are valid with constant objects
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