this post was submitted on 05 May 2025
447 points (98.9% liked)

Programmer Humor

23030 readers
1967 users here now

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

founded 2 years ago
MODERATORS
 
(page 2) 14 comments
sorted by: hot top controversial new old
[–] [email protected] 11 points 1 day ago

Great feature

[–] [email protected] 50 points 1 day ago (1 children)

Another classic javascript wat

[–] [email protected] 4 points 23 hours ago (4 children)

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.

[–] [email protected] 23 points 22 hours ago (5 children)

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!

load more comments (5 replies)
[–] [email protected] 13 points 22 hours ago* (last edited 22 hours ago) (1 children)

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

load more comments (1 replies)
[–] [email protected] 35 points 22 hours ago (11 children)

Javascript could throw an error to alert you that the input is supposed to be a string, like most languages would do.

load more comments (11 replies)
[–] [email protected] 1 points 22 hours ago (1 children)

What do you mean, you don't use string parsing method to round to integers? /s

load more comments (1 replies)
[–] [email protected] 220 points 1 day ago (2 children)

If anyone's wondering why:

>> 0.000005
0.000005
>> 0.0000005
5e-7
[–] [email protected] 76 points 23 hours ago (12 children)

Yup. parseInt is for strings.
Math.floor, Math.ceil, Math.round or Math.trunc are for numeric type "conversions" (cause its still a float)

load more comments (12 replies)
load more comments (1 replies)
[–] [email protected] 99 points 1 day ago (2 children)

It's because parseInt is expecting a string, so the decimal gets converted to a string, and 0.0000005.toString() returns 5e-7.

[–] [email protected] 30 points 23 hours ago* (last edited 22 hours ago) (1 children)

And to further expand on that, if you do pass in a ~~sting~~ string, it handles it correctly.

> parseInt('0.0000005')

0
[–] [email protected] 16 points 22 hours ago* (last edited 7 hours ago) (2 children)

What if I pass in a Stewart Copeland?

[–] [email protected] 8 points 22 hours ago

😆 I'll be watching you...

load more comments (1 replies)
[–] [email protected] 40 points 1 day ago (1 children)
load more comments (1 replies)
load more comments
view more: ‹ prev next ›