How internally JavaScript compare?
alert(022 > "21"); // false
alert(22 > "21"); // true
alert("22" > "21"); // true
I was reading one article here, and it looks that according to that the first should be true
.
How internally JavaScript compare?
alert(022 > "21"); // false
alert(22 > "21"); // true
alert("22" > "21"); // true
I was reading one article here, and it looks that according to that the first should be true
.
In JavaScript, any numeric literal starting with 0
is considered as an octal number. So
console.log(022);
# 18
That is why console.log(022 > "21");
evaluates to false
.
If you want to know how comparing these two entities work, please check the ECMA 5.1 standard specification for The Abstract Relational Comparison Algorithm
Checking that strings are integers is separate to comparing..
See this link: Javascript string/integer comparisons