I understand that a lot of you will disagree with me. This is extremely opinionated, and you don't have to agree.
JavaScript was made in ten days (originally), but it still shows.
Reasons
No strict typing
I do not like the fact that JavaScript has no strict typing. I know that some people like that all of their variables are dynamic, but not me. I also do know about TypeScript, but I think that it is redundant (that is a topic for another article).
Only web language
It is, unfortunately, the only web language. So we have to use it all the time. I understand WebAssembly exists, but it is harder than JavaScript, and it must still be called by a JavaScript script.
The equality operator (==)
How is NaN
not equal to NaN
? Try running the following JavaScript anywhere:
if (NaN == NaN) {
console.log('This makes sense.');
} else {
console.log('This is really silly.');
}
It will output This is really silly.
Somehow, [] == 0
is true
, and NaN == NaN
is false
.
There are so many other things wrong with the equality operator.
There is a ===
operator, which does not try to convert types, but it requires an extra equals. In my opinion, the ==
should not convert types, and we shouldn't even need the ===
.
Weird behaviour
[] + [] // => "" - Somehow gives an empty string
[] + {} // => [object Object] - ok, this makes sense...
{} + [] // => 0 - why does this not give the same as above?!
{} + {} // => NaN - why? They're objects, and it's addition!
Too many frameworks and libraries!
I should not, when starting a new project, have to choose between frameworks. That is insane. If I am, say, making the frontend for a bank, I should not be asking myself, "Should I use Angular? Or React? Probably React. No, wait, Vite! Or Svelte!" No other language has this problem.
The var
keyword
It's highly recommended that you don't use it. So the why does it exist?! All of the ways to declare a variable
let a = 5; // good
const b = 6; // good
var c = 7; // bad
d = 8; // awful
Why does assignment have so many options when only 2 are good? I do not know, and I hate it.
Other stuff
- The this keyword is a nightmare
- NodeJS: taking user input is like rocket science
- NPM is terrible
-
this
keyword is honestly messed up - And so much more...
Top comments (2)
You can get strict typing in plain JS (enforced via your editor/build tools etc) using JSDoc and adding a
// @ts-check
magic comment at the start of a file (or enabled at project level with"checkJs": true
intsconfig.json
).Basically true, but what else do you expect? Native, built-in support for many full-fledged programming languages in every browser? Going back to the bad old days of Java applets? Besides, there are various ways you can use other languages in the browser, enabled with compile-to-JavaScript or compile-to-WASM tooling. See Blazor, Phoenix LiveView, HTMX, Elm, etc. etc.
Yeah,
==
is trash, so set up your linter to disallow it (except for checking nullishness with== null
). Use===
everywhere else.TypeScript/strictly-checked JS files will disallow all of those.
Very true, but that's the tradeoff for massive popularity and adoption and a thriving ecosystem.
Again, disallow in your linter.
For backward-compatibility reasons. Many of JS's weirder features/antifeatures exist purely for historical reasons, because strong backward-compatibility (i.e. not "breaking the web") is a key design goal of newer versions of JS. Websites that haven't been updated in the past 20 years ago should continue to function as intended.
Not necessarily — if
d
has already been declared withlet
, that's the correct way to reassign it. But again, a good linter will help with all this stuff.Agree,
this
is trash. Once again, strong typing helps a lot, though.Using Deno advoids both these problems 😉
I'm curious how taking user input is like rocket science in NodeJS, though?
You make extremely good points for most of them.
d = 8
, I meant without declaring first. That is not good. If it's been declared, then it's good.