LearnFrenzy
Sign in Take a free test

Destructuring · Predict the Output · Question 16

Destructuring assignment with defaults Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 16 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.js
let a = 1, b = 2;
[a = 5, b = 6] = [undefined, null];
console.log(a, b);
  • A 1 2
  • B 5 6
  • C undefined null
  • D 5 null Correct
Correct Answer: Option D

Assignment patterns use the same default rules: undefined triggers the default, null does not. The old values 1 and 2 play no part.

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