this post was submitted on 03 Jan 2025
99 points (95.4% liked)
Programming
17752 readers
1043 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities [email protected]
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
TBF (I don't often defend JS) - one of those is just "standard floating point issues" that every developer should be aware of. Computers cannot represent an infinite array of numbers between 0 and 1.
The first four of them are "just how floats work", yeah. Has nothing to do with JavaScript.
Classic, yes, very funny. "NaN stands for 'not a number' but it says it's a number". But for real though. It's still a variable that's the Number type, but its contents happen to be invalid. It's Not a (Valid) Number.
The next three are just classic floating point precision moments.
The
Math.max()
andMath.min()
ones are interesting. Seems that under the hood, both methods implicitly have a fallback "number" that it compares to any argument list you give it that will auto-lose (or at closest, tie) with any other valid number you can possibly give it, so when you give it nothing at all, they leak out. Honestly, makes sense. Kinda ludicrous it needs to have defined behavior for a zero-argument call in the first place. But JS is one of those silly languages that lets you stuff in or omit as many arguments as you want with no consequences, function signature be damned. So as long as that paradigm exists, the zero-argument case probably ought to do something, and IMO this isn't the worst choice.Every other one is bog standard truthy/type coercion shitlery. A demonstration of why implicit type coercion as a language feature is stupid.