LearnFrenzy
Sign in Take a free test

Destructuring · Find the Error · Question 8

Error: an array pattern on a plain object Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

The code below stops with an uncaught error. Which statement correctly describes the problem?

main.js
const point = { x: 3, y: 4 };
const [x, y] = point;
console.log(Math.hypot(x, y));
  • A It prints 5
  • B It prints NaN
  • C TypeError: point is not iterable – use an object pattern: const { x, y } = point Correct
  • D SyntaxError
Correct Answer: Option C

Array patterns need an iterable. Plain objects are destructured by name with { }.

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