0
0
Javascriptprogramming~20 mins

Adding and removing properties in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Property Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2: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);
ATypeError
B{"a":1}
Cundefined
D{"a":1,"b":2}
Attempts:
2 left
πŸ’‘ Hint
Adding a property to an object uses dot notation and changes the object.
❓ Predict Output
intermediate
2: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);
A{"x":10,"y":20}
B{"y":20}
Cundefined
DSyntaxError
Attempts:
2 left
πŸ’‘ Hint
The delete operator removes a property from an object.
❓ Predict Output
advanced
2: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);
A{"shape":"circle","key":"red"}
B{"color":"red"}
C{"shape":"circle","color":"red"}
DReferenceError
Attempts:
2 left
πŸ’‘ Hint
Bracket notation allows using variables as property keys.
❓ Predict Output
advanced
2: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);
A42
Bundefined
CTypeError
DSyntaxError
Attempts:
2 left
πŸ’‘ Hint
Non-configurable properties cannot be deleted.
🧠 Conceptual
expert
2:00remaining
Which option causes a runtime error when adding/removing properties?
Which of the following code snippets will cause a runtime error when executed?
Aconst obj = Object.freeze({a: 1}); obj.b = 2;
Bconst obj = {a: 1}; delete obj.a;
Cconst obj = {}; obj['b'] = 3;
Dconst obj = {a: 1}; obj.a = 5;
Attempts:
2 left
πŸ’‘ Hint
Frozen objects cannot be changed; adding properties throws error in strict mode.