Why Javascript is my Favourite Language
I genuinely am a big fan of JavaScript; it is hands down my favorite language. Most developers do not agree with me, but I think I am right for good reason.
What makes JavaScript so special?
JavaScript evolved over time while most languages were designed that way. This is very similar to the English language.
English was born out of many cultures, either by them invading us, or us invading them. Spanish and Chinese are the most popular first spoken languages, but English is the world's most popular second language. JS very much like that also.
JS was designed to make HTML pages more interactive when no other language could; it then evolved into the power behind all interactive content, and then finally became a full-stack language in its own right with the creation of Node. It does not matter if you are a full-stack developer specializing in Java, Python, PHP, Rust, Go, etc, you still need to know know JS.
Why the hate?
It's because developers see it as a second-tier language. They like strongly typed languages with well-defined rules. I'd argue this is like training wheels on a bike. You are relying on the language to keep you correct, but you should work in a way that does not allow those types of errors to occur in the first place.
In the backend, you should follow TDD and build in small increments. In the frontend, you should build in increments against the browser. This is all a moot point because TypeScript exists, so you can build JS in a strongly typed way.
That speaks to the language's flexibility, which is uncommon in all other languages, including Python, but Python does come close!
JS is a flexible language, which most developers fail to exploit
Most developers choose to impose their worldview on JS, rather than being flexible and tailoring JS for each task. The result of this is that JS projects are more expensive to run and maintain.
A strictly typed language is better than JS at being strict. An OO language is better at OO than JS. A functional language is better than JS at being functional. None of them are good at being flexible, none of them can work on multiple platforms. If you exploit that, you can build anything, and you can save. No one does this.
Here are some examples that prove my point:
Microservices
TypeScript microservices should not exist. A true microservice is no more than a few methods long; there is no benefit in using TS in this type of project. TypeScript should be used for large projects; it's not needed here. However, developers up and down the country build TS services. The resulting code is harder to maintain and test. Pure JS projects are not only easier to work with, they inherit types from other projects built with TypeScript. There is no benefit in building TS services; you should be using pure JS!
SPAs
Objects in most SPAs are not needed. If you build in a functional way with TypeScript, the resulting app is simpler to manage and easier to maintain because of TS guardrails. Unfortunately most developers use objects because they come from OO backgrounds. Web applications are rarely complex enough to justify their use.
The only real exception is canvas-based apps. If you are working with a canvas, you are writing a lot of code, so objects are very useful.
Databases
Databases; this particular topic makes my blood boil! Developers are using ORMs in JavaScript purely because they are familiar, and their excuse is that they want to work with multiple databases. In Java for example, ORMs are the only way to do that(Hibernate, iBatis).
In terms of working with multiple databases in JS, Knex is all you need! If you want structure and want to work with any database, let me introduce you to Kysely. There is no benefit to using ORMs in a project.
This is what an ORM does in a service: It takes JSON from a database, then converts it to heavy-duty objects, which are then used for simple changes that spawn a lots of processes, and are then converted to JSON for use as service output. If you are using an Object-Oriented language you cannot skip the conversion; this logic makes sense. JS does not need to convert it in the first place; you are adding complexity for no reason. JS already speaks JSON; JSON stands for JavaScript Object Notation! You simply pull it out of the database and output it in the service.
Why is TypeORM used everywhere?!
Large Monoliths
Use all the safeguards: Objects, TypeScript, linters, and Prettier. If it's in the backend, don't use JS; use a strongly typed language like Java or Scala.
For simple applications, I would use JS full-stack always. For very complex backends, I would use a strongly typed language and not JS.
In Conclusion
JS is not like all the other languages because it's flexible and you should exploit that. It does not do OO or functional well, so use those languages when the application demands it.
Don't hate JS; that's just silly because it is really useful.
If I have learned one thing over the years, it's: Let the problem dictate the solution, not the human!