26
you are viewing a single comment's thread
view the rest of the comments
[-] TwilightKiddy@programming.dev 1 points 1 year ago* (last edited 1 year ago)

This one is one of my favourite JS quirks:

JS quirk

[-] LeFrog@discuss.tchncs.de 0 points 1 year ago
[-] usernamesAreTricky@lemmy.ml 1 points 1 year ago

parseInt is meant for strings so it converts the number there into a string. Once the numbers get small enough it starts representing it with scientific notation. So 0.0000001 converts into "1e-7" where it then starts to ignore the e-7 part because that's not a valid int, so it is left with 1

https://javascript.plainenglish.io/why-parseint-0-0000001-0-8fe1aec15d8b

this post was submitted on 16 Jun 2023
26 points (93.3% liked)

Programmer Humor

32171 readers
711 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS