Question 12
Back to Exercise
What does the following JavaScript code print (console output, as in Node.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!