Challenge - 5 Problems
Property Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
β Predict Output
intermediate2:00remaining
What is the output after adding a property?
Consider the following JavaScript code. What will be logged to the console?
Javascript
const obj = {a: 1}; obj.b = 2; console.log(obj);
Attempts:
2 left
π‘ Hint
Adding a property to an object uses dot notation and changes the object.
β Incorrect
The property 'b' is added with value 2, so the object now has keys 'a' and 'b'.
β Predict Output
intermediate2:00remaining
What happens after deleting a property?
What will be the output of this code snippet?
Javascript
const obj = {x: 10, y: 20}; delete obj.x; console.log(obj);
Attempts:
2 left
π‘ Hint
The delete operator removes a property from an object.
β Incorrect
Deleting 'x' removes it from the object, leaving only 'y'.
β Predict Output
advanced2:00remaining
What is the output after adding a property with a variable key?
What will this code print to the console?
Javascript
const key = 'color'; const obj = {shape: 'circle'}; obj[key] = 'red'; console.log(obj);
Attempts:
2 left
π‘ Hint
Bracket notation allows using variables as property keys.
β Incorrect
The variable 'key' holds 'color', so obj['color'] = 'red' adds that property.
β Predict Output
advanced2:00remaining
What error occurs when deleting a non-configurable property?
What will happen when running this code?
Javascript
const obj = {}; Object.defineProperty(obj, 'fixed', { value: 42, configurable: false }); delete obj.fixed; console.log(obj.fixed);
Attempts:
2 left
π‘ Hint
Non-configurable properties cannot be deleted.
β Incorrect
Deleting a non-configurable property fails silently in non-strict mode, so the property remains.
π§ Conceptual
expert2:00remaining
Which option causes a runtime error when adding/removing properties?
Which of the following code snippets will cause a runtime error when executed?
Attempts:
2 left
π‘ Hint
Frozen objects cannot be changed; adding properties throws error in strict mode.
β Incorrect
Object.freeze makes the object immutable. Adding properties throws a TypeError in strict mode.