Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

Why is "10" < "9" true in JavaScript?

Do you know what will be the output of this code?

JavaScript
console.log("10" < "9");
Show answer and explanation

The answer is true.

When both sides are strings, < compares them lexicographically, one character at a time. "1" has a lower character code than "9", so the comparison ends there.

Convert to numbers first: Number("10") < Number("9") is false.

Take the full quiz Next question →

More Strings questions

  1. Why does ('b' + 'a' + + 'a' + 'a') return "banana"?
  2. Why is "a string" instanceof String false?
  3. Why does 1 + "2" + "2" return "122"?
  4. What does String.raw do in JavaScript?
  5. Can you change a character in a JavaScript string?

Related topics