LearnFrenzy
Sign in Take a free test

Arrays · Predict the Output · Question 12

join with null and undefined Answer, explanation & discussion

  • Output
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

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

main.js
console.log([1, null, undefined, 2].join("-"));
console.log(String([[1, 2], [3]]));
  • A 1-null-undefined-2 1,2,3
  • B 1--2 [1,2],[3]
  • C 1-0-NaN-2 1,2,3
  • D 1---2 1,2,3 Correct
Correct Answer: Option D

join turns null and undefined into empty strings. Nested arrays are converted with their own join(","), so the nesting disappears.

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