- Posted in:
Low barrier of entry
.js extension, you can embed it in a webpage to run it in a web browser, or install a runtime (Node.js/Deno/Bun) to run it on your computer like any other program. Wait a minute… it’s actually easier than that! You can go to CodeSandbox, CodePen, StackBlitz or any other online code app and write and test your JS there!
As a language, JS is forgiving. Reassigning a variable with a different type than the original value? No problem! Although this “feature” fools everyone at least once in their career, the dynamically typed nature of JS allows users to get started with little theory. Users don’t need to trouble themselves with data types, access modifiers, immutability, whatever. They just get to code. Because JS doesn’t enforce a paradigm (e.g. OOP or FP), beginners can start by writing little scripts and get into programming paradigms later.
After writing some code, we want to deploy it. A web application with client-side JS can be hosted anywhere that supports static hosting, that various services provide freely: GitHub Pages, Netlify, and Vercel, just to name a few. Hosting your own Node.js server on a VPS is a bit fiddly, which is probably why cloud functions are immensely popular. Cloud function providers often take away a lot of complexity like security, stability, and making your code run on a server. Next to being easier to work with, many providers also offer a free tier!
It’s objectively good
Being built for browsers, JS is designed to avoid blocking the UI and heavily relies on events to run small snippets of code. As a consequence, functions are first-class citizens, which turns out to be very handy, like for reusability and extensibility.
The asynchronous nature allows JS runtimes to be single-threaded using an event loop. Unfortunately, it makes code execution order unpredictable and requires some understanding of scopes (i.e. when variables are and aren’t available).
All of this makes JS a solid language for UIs, which explains why people choose web technology to build mobile and desktop applications using tools like React Native. In fact, the Microsoft Flight Simulator UI was written in HTML, CSS, and JS! Web technology in a game 🤯
When much of your code consists of callbacks and runs in arbitrary order, it creates some pitfalls, like callback hell and the assumption events are triggered (and callbacks are called) in a specific order. All of these can be mitigated by learning about
Promises, async functions, and by avoiding relying on event handlers execution order. If you’re a beginner or considering learning JS, you might not get any of this lingo yet, and that’s fine — you will cross that bridge when you get there.
The quirks and pitfalls are a mere consequence of being optimized for a specific purpose. That doesn’t make it bad, that makes it specialized.
Despite its bad reputation, JS never lost its dominance on the web, gained much popularity as a server-side alternative shortly after Node.js was released, and continues to be a popular choice for mobile and desktop applications.
If you’re not hyped about JS, that’s alright. About ⅓ dread the language. But remember the power JS gives you: with it, you can build just about anything!