3 ms·
Is anyone else bothered by the following? isOdd('1'); //=> true String input to a function that checks on numbers is considered valid?
by siddhant 8y ago
Is anyone else bothered by the following?
isOdd('1');
//=> true
String input to a function that checks on numbers is considered valid?
- HelloNurse 8y agoThe Javascript tradition is coercing '1' to 1, so it is a number for most practical purposes. A language with more restrained type conversion rules would have a different, and more trivial, isOdd() function.
- caspervonb 8y agoPersonally I'd just let that be UB; garbage in, garbage out.