by pzmarzly · 2y ago · 0 comments
- No control over integer type. Everything is a double, except that it sometimes behaves like int for bitwie operation. You lose precision easily and silently. BigNum support is ugly.
- Standard library is one of the worst among all languages, it's inconsistent and missing many basic functions.
- Implicit type casting means you are better off always using === and never relying on truthiness (ie. in "if (...)" better make sure this ... evaluates to true or false, not {}, null, etc, or else you will be surprised by 0).
- We have both exceptions and 2 special marker types (null, undefined). Different libraries will use different methods to signify errors. See Rust for how to do this well.
- Prototype based inheritance sometimes leaks as an abstraction. The only languages I know of that use prototypes are JS and Lua.
This is in part because JS’s exceptions support is the worst: catch clauses can’t be filtered by type so you have to catch/filter/rethrow, and before ES6 subtyping Error was essentially impossible.
So even if you are fine with exceptions, you don’t want to use them in JS. Even more so before async proper as they obviously did not work correctly through callback chains.
The same applies to the "standard library", which is really just a collection of helper functions under the umbrella of a few top-level built-in objects to keep the core language clean.
I'd rather blame the generations of devs implementing add-ons and syntactic sugar according to the fashion of the day and mimicking their respective favorite language, which adds loads of inconsistencies to the various extensions of the language (often leading to duplicate mechanisms and implementations), depending on when it was done. So there is no common way of communicating with these interfaces and no implicit design philosophy (it may be JFX-style, callback based, a promise, functional, whatever). This is even true for the core language, e.g., arrow-functions breaking the basic convention of arguments always coming as a list.
The idea that it needs a better standard library is deeply tied to the idea that it should be used as an applications language, but that's actually kind of a recent idea with the advent of runtimes like Node and later Deno and Bun. And all of these do include bigger standard libraries.
I think part of the reason JS has become so popular as both an embedded and application language is that it doesn't have a standard library that needs to be shipped to all embedders/implementations. That's what Java does. And Java lost a lot of ground to JS over the years.