This is because the first character "12" is 1 , which precedes "2" ; and string comparison in JavaScript is lexically / alphabetically, not numerically. Although it looks partially numeric, since 1 sorted ahead of 2 .
However, you can simply compare numbers as numbers:
document.write(parseFloat("12") < parseFloat("2"));
source share