DEV Community

Where Javascript Coercion went wrong?

alokz diptim! on January 02, 2019

Coercion is unknowingly the conversion of a datatype to another with the use of the Javascript engine. One of the few surprises in Javascript. No...
Collapse
 
somedood profile image
Basti Ortiz

console.log(1 < 4 < 3); it will return true instead of false because the javascript sees it as:
console.log(true < 3);
“true” would be coerced to 1 and when compared will be 1 < 3 which will be true.

I never knew that. I had always thought it was just a quirk of JavaScript. Thanks for clearing things up!

Collapse
 
aloksdiptim profile image
alokz diptim!

Yes, it is because of coercion.

Thanks for reading the post.