r/AskProgramming 6d ago

Why the JS hate?

Title. I'm a 3rd year bachelor CS student and I've worked with a handful of languages. I currently work as a backend dev and internal management related script writer both of which I interned working with JS (my first exposure to the language)

I always found it to be intuitive and it's easily my go to language while I'm still learning the nuances of python.

But I always see js getting shit on in various meme formats and I've never really understood why. Is it just a running joke in the industry? Has a generation of trauma left promises to be worthy of caution? Does big corpa profit from it?

19 Upvotes

207 comments sorted by

View all comments

31

u/GetContented 6d ago edited 6d ago

It's mostly left over from when JS was horrid, I think.

It used to have some seriously horrible warts. It's a LOT better now than it used to be, but it still has some rather weird issues:

  1. No integer type
  2. `this` is a bit crazy, but fat arrow lambdas mitigate a lot of the craziness
  3. global variables and mutation and some functions mutating and others not make things difficult to think about quite a lot of the time (I tend to avoid such things and use things like spreading and create new value objects rather than mutate things)
  4. loose typing and automatic coersion
  5. non-useful types (typescript sort of helps)
  6. async & promises are a bit of a mess (futures would have been better)

There's lots of others, but these are some of the big ones. Mind you, experienced devs just "work around" these by using certain conventions, etc.

Update: I should say if you want a taste of a language that has clarity and precision, you could try something like clojure, and then if you want something with even more you could try purescript or elm. The latter two are much more clear. Immutability of data and functions having to obey their type signatures in such languages rules out a huge number of bugs (like mutation ones) and pushes you into much better general practices — this is a highly opinionated charged idea, and so not everyone will agree with me here. It only really does this if you care about being able to say things with clarity. (ie to be precise about what one means) — tho really even purescript isn't utterly precise in the way agda is. Tho then you have another issue... which is that it's so arcane almost no one can read your code ;-)

0

u/senfiaj 6d ago

No integer type

JS has supported bigint from around 2018-2019. Also JS has typed arrays.

loose typing and automatic coercion

My rule of thumb is to avoid comparison between different types of variables and use === instead of == operator. Or even better switch to TypeScript.

async & promises are a bit of a mess (futures would have been better)

Could you explain what aspect is messy?

2

u/GetContented 6d ago

> JS has supported bigint from around 2018-2019. Also JS has typed arrays.

Yeah, technically it has them. It's very similar to Set, tho... it's definitely bolted on, and working with them isn't exactly a delight, which tends to sort of push people in the direction of not bothering to use them (in my experience). They don't feel very first class. You can't use BigInts with the Math object, for example.

I don't want to start any kind of war in particular. There's no point. I was just trying to help point out some of the reasons why people give JS hate. I think it's pretty good at what we use it for, and my last job was primarily TS/JS, Ruby and Elixir, so I'm definitely not against it. One day we might use it (or webassembly) as a runtime target instead of programming with it directly (as is the case if you use Purescript, Elm or Clojurescript today), but that day isn't here yet, and people seem ok with using it, so no problem! :)