LearnFrenzy
Sign in Take a free test

JavaScript Basics · Predict the Output · Question 2

Left-to-right + with strings Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 Back to Exercise

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

main.js
console.log("2" + 3 + 4);
console.log(2 + 3 + "4");
  • A 9 9
  • B 234 234
  • C 234 54 Correct
  • D 27 54
Correct Answer: Option C

+ is evaluated left to right. "2" + 3 is "23", then "234". In the second line 2 + 3 is 5 first, then 5 + "4" is "54".

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