0
Why "12" > "2" return false??
11 Respuestas
+ 16
If you compare strings, the comparison is character by character. And in this case 2 is greater than 1
+ 3
Codenath You (probably) got a point right there!
+ 3
javascript is quirky though...
it allows
console.log("12">"2")
console.log("12">2)
console.log(12>"2")
console.log(12>2)
things you can't do in other languages.So you have to be extra careful.
+ 3
Bob_Li ya it will will simply an error if we compare a string with a number , i don't know much about js but in c++ according to my knowledge it will give error too
+ 2
This is because you're comparing string..
+ 2
Hariharan here , both 12 and 2 are string if you convert them int int the output will be true (1)
+ 2
Alhaaj or even just one of them. If not set on strict mode, javascript takes the liberty of converting the other string to number, which while convenient in some cases, is generally considered a sloppy behavior. Strict mode would throw an error if you compared numbers and strings.
+ 2
Comparison between strings always compare their first character then second then on.
you put quotation marks in value hence it means it is a string, so please remove, if you want to make it a integer.
If liked my answer please upvote.
+ 1
Yo guys?
+ 1
Do you mean "string" > "string"? Of course it will be return false, Please remove " symbol from your integer
0
Thank you all ☺