4 ms·
Since comparing strings and numbers generally doesn't make a lot of sense, you could just consider it a case of "undefined behavior". As many other people will
by jkrems 13y ago
Since comparing strings and numbers generally doesn't make a lot of sense, you could just consider it a case of "undefined behavior". As many other people will write: There's only one case I can think of where the unsafe-equals operator is reasonable and that's `a == null` to check for null/undefined.
- jonpaul 13y agoYep. Along with `== null`. I also only use "==" with `typeof` since `typeof` always returns a string.
- marcosdumay 13y agoMost languages call those situations by the name "runtime error", that is, when it is even possible that they happen at runtime. Now, I understand that javascript runs in a completely different kind of environment, and it does have the liberty of making things differently, up to a certain point. But making '' == 0 true may be a bit too far.. And making [1] == 1 true is clearly too far.