DEV Community

Discussion on: 10 JS tricks you *probably* didn't know

Collapse
 
hnicolas profile image
Nicolas Hervé

You should stop using "tricks" to convert types in javascript and start using explicit type conversion.
Implicit type conversion is bad for readability and leads to errors.
Your "trick" number 9 prove my point : it does not compare 3 values like you say but instead evaluate 3 > 2 which returns false, then implicitly convert false to 0 because a boolean cannot be compared to a number, then it returns the result of 0 < 5 which is true.
Try 2 > 0 < 1 and you will see it does not work.

Try number 10 with a Date object or any other object that define the toJSON method...