▲ 20 ▼ Yup, Javascript can go F@#! itself (lemmy.ml) submitted 3 years ago by OsrsNeedsF2P@lemmy.ml to c/programmerhumor@lemmy.ml 17 comments fedilink hide all child comments
[–] TwilightKiddy@programming.dev 1 point 3 years ago* (1 child) This one is one of my favourite JS quirks: permalink fedilink source hideshow 2 child comments replies: [–] LeFrog@discuss.tchncs.de 0 points 3 years ago (1 child) Wait wtf is happening there? permalink fedilink source parent hideshow 2 child comments replies: [–] usernamesAreTricky@lemmy.ml 1 point 3 years 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 permalink fedilink source parent
[–] LeFrog@discuss.tchncs.de 0 points 3 years ago (1 child) Wait wtf is happening there? permalink fedilink source parent hideshow 2 child comments replies: [–] usernamesAreTricky@lemmy.ml 1 point 3 years 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 permalink fedilink source parent
[–] usernamesAreTricky@lemmy.ml 1 point 3 years 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 permalink fedilink source parent