LearnFrenzy
Sign in Take a free test

Operators · Predict the Output · Question 8

Comparing numeric strings Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

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

main.js
console.log("2" > "12", 2 > "12", "b" > "a");
  • A false false true
  • B true true true
  • C true false true Correct
  • D false true false
Correct Answer: Option C

Two strings compare character by character: "2" > "1", so "2" > "12". With one number, the string is converted: 2 > 12 is false.

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