Question 10
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
console.log(JSON.stringify([] + []), [] + {}, [1, 2] + [3]);
- A [] [object Object] [1,2,3]
- B 0 NaN 6
- C "" [object Object] 1,23 Correct
- D "" {} 1,2,3
Correct Answer: Option C
+ converts objects to primitives: [] becomes "", {} becomes "[object Object]", [1, 2] becomes "1,2". Then the strings are concatenated.
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!