Oh JavaScript... This is why we don't get along.
Jan 27, 2024 · 10:33 PM UTC
121
170
2,353
745,006
@eloffd parseInt is for strings, so it is trying to do parseInt('5e-7'), which is 5. In this case, it is recommended to use: Math.floor
11
10
478
24,915
@eloffd Are you from the Typescript sales department, sir?
1
0
1
350
@garyfung I should be, the amount of times I plug it on here, they need to put me on commission
0
0
1
304
@eloffd I hate parseInt 😭😭 I forget this at least once a year and I'm like... TF
1
0
1
1,982
@eloffd “Parse int is for strings”
Doesn’t matter - this makes no lexical sense so it’s not something that should be accepted.
Doesn’t matter - this makes no lexical sense so it’s not something that should be accepted.
3
1
96
16,024
@FnH How does this even work?
"The default sort order is ascending, built upon converting the elements into strings, then comparing their sequences of UTF-16 code units values."
That's INSANE. Still I don't see how it gets that result?
"The default sort order is ascending, built upon converting the elements into strings, then comparing their sequences of UTF-16 code units values."
That's INSANE. Still I don't see how it gets that result?
3
1
30
14,794
@eloffd This is forcing the square peg into the round hole, and crying it broke eventually.
1
0
34
3,871
@TheMeowku The round hole should throw an error when it gets a square peg. It shouldn't put in on a lathe to try to carve off the edges.
2
0
25
3,487
@eloffd It's funny as well as scary that the whole world directly or indirectly depends on such a bad language.
1
0
18
5,445
@eloffd This is totally correct: parseInt parses a string, discarding any non-integer rest, and 0.0000005 rendered as a standard string "5e-7". So, what is the leading string? Well, 5.
However, parsing an actual string by 'parsInt("0.0000005") gives you 0.
(For numbers use Math.floor!)
However, parsing an actual string by 'parsInt("0.0000005") gives you 0.
(For numbers use Math.floor!)
1
1
9
2,678









