LearnFrenzy
Sign in Take a free test

Operators · Predict the Output · Question 1

Arithmetic on numeric strings Answer, explanation & discussion

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

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

main.js
console.log("10" - 4, "10" * "2", "10" / "4", "abc" * 2);
  • A 106 1010 2.5 NaN
  • B 6 20 2 abcabc
  • C NaN NaN NaN NaN
  • D 6 20 2.5 NaN Correct
Correct Answer: Option D

-, * and / convert strings to numbers. "abc" converts to NaN, and any arithmetic with NaN is NaN.

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