Question 2
Back to Exercise
JavaScript refuses to run the code below. Which statement correctly describes the problem?
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!