LearnFrenzy
Sign in Take a free test

Destructuring · Predict the Output · Question 1

Array defaults with undefined and null Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 1 Back to Exercise

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

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

b is undefined, so its default applies; c is null, which is a real value, so its default does not.

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