LearnFrenzy
Sign in Take a free test

Operators · Predict the Output · Question 10

Adding arrays and objects Answer, explanation & discussion

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

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

main.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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links