LearnFrenzy
Sign in Take a free test

Destructuring · Exercise 1 of 4

Destructuring Destructuring MCQ

  • 15 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Fifteen multiple-choice questions on JavaScript destructuring: array and object patterns, skipping, defaults, renaming, rest, nested patterns, parameters, assignment syntax, iterables and errors. Pick an option to check your answer instantly.

Question 1 Easy

How do array and object destructuring decide which value goes into which variable?

A Both match by position
B Both match by name
C Array patterns match by position; object patterns match by property name
D Array patterns match by name; object patterns by position
Question page & discussion
Question 2 Easy

For const { theme = "light" } = settings;, which value of settings.theme makes theme equal to "light"?

A null
B undefined (or a missing property)
C "" (empty string)
D false
Question page & discussion
Question 3 Easy

What does const { name: fullName } = user; do?

A Creates a variable name holding user.fullName
B Creates both name and fullName
C Sets user.fullName to user.name
D Creates a variable fullName holding user.name
Question page & discussion
Question 4 Medium

Which pattern reads obj.size into a variable s, defaulting to 10?

A const { size: s = 10 } = obj;
B const { s: size = 10 } = obj;
C const { size = 10: s } = obj;
D const { s = size: 10 } = obj;
Question page & discussion
Question 5 Easy

Which destructuring pattern is valid?

A const [...rest, last] = arr;
B const [first, ...a, ...b] = arr;
C const [first, ...rest] = arr;
D const { ...rest, id } = obj;
Question page & discussion
Question 6 Medium

What happens with const { id } = null;?

A id becomes undefined
B id becomes null
C A SyntaxError
D TypeError: Cannot destructure property 'id' of null
Question page & discussion
Question 7 Hard

Variables a and b already exist. Which statement assigns obj.a and obj.b to them?

A { a, b } = obj;
B ({ a, b } = obj);
C let { a, b } = obj;
D [a, b] = obj;
Question page & discussion
Question 8 Easy

Which pattern takes only the third item of arr?

A const [, , third] = arr;
B const [third] = arr[2];
C const [3: third] = arr;
D const { third } = arr;
Question page & discussion
Question 9 Medium

After const { password, ...safe } = user;, what is safe?

A The user object itself without password (user is changed)
B An array of the remaining values
C A new object with all of user's own enumerable properties except password
D Only the next property after password
Question page & discussion
Question 10 Hard

In const { city = fetchCity() } = data;, when is fetchCity called?

A Every time the line runs
B Never – defaults must be constants
C Only if data.city is falsy
D Only if data.city is undefined
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links