3 ms·
It depends [] % 2 === 0 //true [234] % 2 === 0 //true "" % 2 === 0 //true new Date() % 2 === 0 //sometimes true
by yulaow 5y ago
It depends
[] % 2 === 0 //true
[234] % 2 === 0 //true
"" % 2 === 0 //true
new Date() % 2 === 0 //sometimes true
- aww_dang 5y agoThis is the kind of nonsense I imagine when people complain about strong types and verbose languages. "but think of all of the time and keystrokes I saved by not having to call .toString()!", they'll say...
- throw_m239339 5y agothis is type coercion at work. If you have that kind of problem then maybe you should sanitize whatever the input is first, then check with parseFloat and isNaN if the value IS a number. If you are sending arrays to your modulo check then obliviously your code has a logical error.