DEV Community

Kaamkiya
Kaamkiya

Posted on

Why I hate JavaScript 🤷

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.');
}
Enter fullscreen mode Exit fullscreen mode

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!
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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)

Collapse
 
lionelrowe profile image
lionel-rowe

No strict typing

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 in tsconfig.json).

Only web language

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.

The equality operator (==)

Yeah, == is trash, so set up your linter to disallow it (except for checking nullishness with == null). Use === everywhere else.

Weird behaviour

TypeScript/strictly-checked JS files will disallow all of those.

Too many frameworks and libraries!

Very true, but that's the tradeoff for massive popularity and adoption and a thriving ecosystem.

The var keyword

Again, disallow in your linter.

So then why does [var] exist?!

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.

d = 8; // awful

Not necessarily — if d has already been declared with let, that's the correct way to reassign it. But again, a good linter will help with all this stuff.

Other stuff

  • The this keyword is a nightmare

Agree, this is trash. Once again, strong typing helps a lot, though.

  • NodeJS: taking user input is like rocket science
  • NPM is terrible

Using Deno advoids both these problems 😉

I'm curious how taking user input is like rocket science in NodeJS, though?

Collapse
 
kaamkiya profile image
Kaamkiya • Edited

You make extremely good points for most of them.

  1. That's true, and it does make it easier
  2. I agree, but it would be nice to be able to use WASM (which is built-in) without having to call it from JS
  3. I personally don't use a linter, but you are correct, that would work
  4. Weird behavior: that's a fair point, TypeScript will get rid of all of this. It's still annoying to have to rewrite everything in TS for type safety, though. I wish that was implemented in the first edition of JS.
  5. It is a tradeoff. But even for Python, there aren't that many frameworks/modules. There are plenty, but only the top ~30 are actually used. The rest are just there.
  6. Also fair. When I said d = 8, I meant without declaring first. That is not good. If it's been declared, then it's good.
  7. I guess Deno would help with that.
  8. It's so overcomplicated:
const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

readline.question('Who are you?', name => {
  console.log(`Hey there ${name}!`);
  readline.close();
});
Enter fullscreen mode Exit fullscreen mode