0

Can anyone explain me this Javascript output?

console.log("2" < "12') // false

28th Jun 2020, 4:01 AM
Devansh trivedi
Devansh trivedi - avatar
1 Answer
+ 10
Because "2" and "12" are both string, When comparing string, the charcodes of first characters are compared first because the charcode of "2" is larger than the charcode of "1", so "2" < "12" is false. Get charcode with charcodeAt : https://www.sololearn.com/post/143486/?ref=app More detailed explanation by Omkar : https://www.sololearn.com/post/254575/?ref=app https://code.sololearn.com/WKKkpq0efxai/?ref=app
28th Jun 2020, 4:05 AM
Gordon
Gordon - avatar