Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How "2" < "123" is false in Javascript but not 2 < "123"?

When I am running the mentioned code. What is the reason behind giving it false and not the second one is it related to ascii value or something else I am Unable to get it.
Can anyone explain this?

console.log('2' < '123');
console.log(2 < '123');

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The rules for < say that:

  • (Step 3) If you compare a string to a string: Compare them lexically.

  • (Starting from Step 4c) If you compare a number to a string: Convert the string to a number, then compare them numerically.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading