LearnFrenzy
Sign in Take a free test

Destructuring · Find the Error · Question 2

Error: destructuring assignment without parentheses Answer, explanation & discussion

  • Find the error
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 Back to Exercise

JavaScript refuses to run the code below. Which statement correctly describes the problem?

main.js
let width, height;
{ width, height } = { width: 1920, height: 1080 };
console.log(width, height);
  • A It prints 1920 1080
  • B It prints undefined undefined
  • C SyntaxError: a statement starting with { is a block – wrap the assignment: ({ width, height } = …); Correct
  • D TypeError
Correct Answer: Option C

The parser reads { width, height } as a block statement, and then = has nothing valid on its left. Parentheses make it an expression.

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