LearnFrenzy
Sign in Take a free test

Destructuring · Predict the Output · Question 13

Defaults for a hole and for null Answer, explanation & discussion

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

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

main.js
const [a = "x", b = "y", c = "z"] = [, null];
console.log(a, b, c);
  • A x null z Correct
  • B x y z
  • C undefined null z
  • D x null undefined
Correct Answer: Option A

A hole and a missing item both read as undefined, so a and c get defaults; null is kept for b.

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