+ 1

Help me compare two string of number javascript

why thel result is true Console.log("2">"12") // true I dont understand it

13th Mar 2020, 7:25 AM
MetaCop
MetaCop - avatar
3 Respuestas
+ 4
Because in JavaScript strings comparison is according to the dictionary comparison. in this case, the first character of "2" is greater than the first character of "12" that's why it shows true.
13th Mar 2020, 8:02 AM
Bilal Yoosuf
Bilal Yoosuf - avatar
+ 2
'2' > '1' Like an alphabet
13th Mar 2020, 7:29 AM
Danil SwD
Danil SwD - avatar
+ 1
Thanks!!
13th Mar 2020, 4:25 PM
MetaCop
MetaCop - avatar