0
0
Javascriptprogramming~20 mins

Object use cases in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
πŸŽ–οΈ
Object Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this code using object property shorthand?
Consider the following JavaScript code snippet. What will be logged to the console?
Javascript
const name = 'Alice';
const age = 30;
const person = { name, age };
console.log(person);
A{ name: 'Alice', age: 30 }
B{ name: 'name', age: 'age' }
C{ name: undefined, age: undefined }
DSyntaxError
Attempts:
2 left
πŸ’‘ Hint
Object property shorthand lets you write { name, age } instead of { name: name, age: age }.
❓ Predict Output
intermediate
2:00remaining
What is the output when accessing nested object properties?
What will this code output to the console?
Javascript
const data = { user: { id: 1, info: { name: 'Bob', city: 'NY' } } };
console.log(data.user.info.city);
Aundefined
B'NY'
CTypeError
D'city'
Attempts:
2 left
πŸ’‘ Hint
Access nested properties by chaining keys with dots.
❓ Predict Output
advanced
2:00remaining
What is the output of this code using Object.assign?
What will be logged to the console after running this code?
Javascript
const target = { a: 1, b: 2 };
const source = { b: 4, c: 5 };
const result = Object.assign(target, source);
console.log(result);
A{ a: 1, b: 4, c: 5 }
B{ a: 1, b: 2, c: 5 }
C{ b: 4, c: 5 }
DTypeError
Attempts:
2 left
πŸ’‘ Hint
Object.assign copies properties from source to target, overwriting existing keys.
❓ Predict Output
advanced
2:00remaining
What error does this code raise when accessing a missing property?
What happens when this code runs?
Javascript
const obj = { x: 10 };
console.log(obj.y.z);
AReferenceError
Bundefined
Cnull
DTypeError: Cannot read property 'z' of undefined
Attempts:
2 left
πŸ’‘ Hint
Accessing a property of undefined causes a TypeError.
❓ Predict Output
expert
2:00remaining
What is the output of this code using computed property names?
What will this code print to the console?
Javascript
const key = 'score';
const player = {
  [key]: 100,
  ['level' + 1]: 2
};
console.log(player);
ASyntaxError
B{ score: 100, level: 1 }
C{ score: 100, level1: 2 }
D{ key: 100, level1: 2 }
Attempts:
2 left
πŸ’‘ Hint
Square brackets let you use expressions as property names.