Great feature
Programmer Humor
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
Another classic javascript wat
Classic people who don't know how to code wat. Passing a number in place of a string argument because they don't know what they're doing.
It's not a string argument though, it's JS. You can argue it's expected to be a string but like the rest of JS all you can know from the signature alone is that it takes an object. Hopefully your little ducky quacks the right way!
Could be a variable from somewhere else in the code. It should throw type error of some sort if it's not going to handle a float correctly
Javascript could throw an error to alert you that the input is supposed to be a string, like most languages would do.
What do you mean, you don't use string parsing method to round to integers? /s
If anyone's wondering why:
>> 0.000005
0.000005
>> 0.0000005
5e-7
Yup. parseInt is for strings.
Math.floor, Math.ceil, Math.round or Math.trunc are for numeric type "conversions" (cause its still a float)
It's because parseInt is expecting a string, so the decimal gets converted to a string, and 0.0000005.toString()
returns 5e-7
.
And to further expand on that, if you do pass in a ~~sting~~ string, it handles it correctly.
> parseInt('0.0000005')
0