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!