LearnFrenzy
Sign in Take a free test

Destructuring · Destructuring MCQ · Question 15

An array pattern on an object Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 15 Back to Exercise

What does const [x, y] = { x: 1, y: 2 }; do?

  • A Throws a TypeError – the object is not iterable Correct
  • B x = 1, y = 2
  • C x and y are undefined
  • D A SyntaxError
Correct Answer: Option A

Array patterns use the iteration protocol. Use an object pattern, const { x, y } = obj, or Object.values(obj) with an array pattern.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links