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

Answer & Solution

Answer: Option C
Solution:
javascript const person = { name: 'John', age: 30 }; person.address = '123 Main St'; The code adds the address property to the person object, resulting in 3 properties.
Related Questions on Average

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

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

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

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

What is the correct way to modify a property of a constant object in JavaScript?

A). A. Use the delete keyword

B). B. Use the const keyword for the property

C). C. Use dot notation or bracket notation to access and modify the property

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

What does the const keyword do when used to declare an object in JavaScript?

A). A. Makes the object immutable

B). B. Prevents reassignment of the object reference

C). C. Freezes all properties of the object

D). D. All of the above

Which statement best describes the behavior of a constant object in JavaScript?

A). A. The object and its properties cannot be changed

B). B. The object reference cannot be reassigned

C). C. All properties are immutable

D). D. The object cannot be modified after declaration

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