Today, JavaScript is a general-purpose language. This means it can be executed in a wide variety of environments.
Traditionally, JavaScript has been closely associated with web development (and it still is). But nowadays we can use it in many other areas.
To run JavaScript, we only need an interpreter capable of executing the code.
The interpreter (or runtime) is a program that reads the source code and executes it directly, line by line.
JavaScript in Web Browsers
From its beginnings, one of its main uses has been adding interactivity to web pages. In this context, the web browser itself acts as the JavaScript interpreter.
When a web page loads, the browser (Chrome, Firefox, Safari, etc.) receives the JavaScript code as part of the Web content.
The JavaScript engines built into browsers (like V8 in Google Chrome, SpiderMonkey in Firefox, and JavaScriptCore in Safari) handle the task of interpreting and executing this code.
JavaScript engines have evolved tremendously since the early days of the language. They now incorporate advanced techniques that greatly improve performance (like Just-In-Time compilation).
Running JavaScript in Other Environments
Although the web browser remains a very important environment for running JavaScript, over time other runtimes have emerged that allow JavaScript to be executed outside the browser.
We call this running JavaScript on the server. But the server can be anything, your personal computer. What it means is outside the browser.
Node.js
The first and most famous of these runtimes is Node.js, which was introduced in 2009. Node.js allows running JavaScript on the server, using the V8 engine from Google Chrome.
At the time, this was a revolution because it allowed developers to use JavaScript both on the frontend and backend, and to benefit from its asynchronous, event-based programming model.
Other Runtimes
In recent years, other runtimes have emerged seeking to improve and expand the capabilities of Node.js.
Deno: Created by Ryan Dahl, the same creator of Node.js, Deno was launched in 2020 with the goal of correcting some design mistakes of Node.js. Deno offers a secure environment by default, with explicit permissions for file, network, and other system resource access. Additionally, it supports TypeScript natively and has a URL-based module system.
Bun: It is an emerging runtime designed to be extremely fast, focusing on efficiency and simplicity. Like Deno and Node.js, Bun uses the V8 JavaScript engine, but introduces additional optimizations to improve the performance of JavaScript applications.
These are some of the most well-known, but there are many runtimes, even some very lightweight ones to run on the “edge”.
Learn to develop with Node.js step by step
Other Execution Environments
JavaScript has become so ubiquitous that it can now be found in a wide variety of environments, including:
Desktop Applications
Using frameworks like Electron, it’s possible to build desktop applications with web technologies (HTML, CSS, JavaScript).
Electron is based on Node.js and Chromium, allowing developers to create cross-platform applications.
Mobile Applications
Frameworks like React Native allow developing native mobile applications using JavaScript.
React Native translates JavaScript code into native components, offering a user experience similar to applications written in Swift or Kotlin.
Automation
Tools like Puppeteer and Selenium use JavaScript to automate web browsing tasks and application testing, which is very useful in software development and maintenance.
JavaScript on Hardware Devices
But JavaScript is not limited solely to traditional software environments. We can also run it on hardware devices like Arduino and ESP32 (which we love on this site, you already know ❤️).
For example, Johnny-Five is a JavaScript framework that allows programming embedded systems using JavaScript. (for instance, we can control devices like LEDs, sensors, motors, and other components).
In short, you can use JavaScript in many, many places. It is no longer just a simple scripting language for web browsers.
Today, it is a truly general-purpose programming language that can be executed in a wide variety of environments, from servers to hardware devices and desktop and mobile applications.
