How does this results true? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How does this results true?

let a = '14' < '6' console.log(a) //true

22nd Aug 2020, 10:23 AM
zexu knub
zexu knub - avatar
2 Answers
+ 4
Both are strings! The ascii value matters and not the value of the number Ascii value of '6' > ascii value of '1' Just like english dictionaries where the words are in alphabetical order. Number sometimes make it confusing! But see the ascii table! Everything will be clear
22nd Aug 2020, 10:30 AM
Namit Jain
Namit Jain - avatar
+ 2
Here we are comparing strings "6" and "14". String "6" is lexographically greater than "14". That's why it results true.
22nd Aug 2020, 10:32 AM
Atul