
Overview of JavaScript Environments
So far in our journey, we've only been exposed to the modern web browser as a JavaScript runtime, but even within browsers, there are a variety of JavaScript engines that serve as different runtimes for JavaScript. For instance, Chrome has the V8 engine, while Firefox runs JavaScript through SpiderMonkey. Just about every browser has its own distinct engine.
There are also other runtimes aside from those that are browser-based. We'll have a look at the variety of runtimes available to us now.
Browser-Based JavaScript
By far, the most common environment for using JavaScript throughout its entire history as a language is within the web browser. We've already spoken of this particular runtime quite a lot, so we will not spend time going over all of this again:

Figure 2.20: V8—JavaScript in the web browser
Some of the benefits of using the web browser as a JavaScript runtime are as follows:
- Web browsers are one of the most distributed software platforms in the world.
- Browsers include a set of built-in developer tools for debugging and monitoring JavaScript.
- Browsers are the absolute primary runtime for JavaScript and all others follow it.
You can learn more about each browser runtime at their respective websites. To learn more about V8, the runtime engine powering Chrome, visit https://v8.dev/.
Server-Based JavaScript
With the improvement in the performance of JavaScript engines in the web browser, people began wondering whether there may be other applications for the language and specific runtimes—particularly in terms of a server-based environment. In 2009, this became a reality with the creation of Node.js. A year before this, Google had open-sourced its powerful V8 JavaScript engine. This allowed developers to implement V8, along with specific operating system bindings, to produce the first version of Node.js:

Figure 2.21: Node.js—JavaScript on the server
The benefits of using a server-based JavaScript runtime include the following:
- Threadless execution of code.
- Events are completely non-blocking.
- Efficiency and performance are separated from the client.
You can learn more about Node.js at https://nodejs.org/.
Desktop JavaScript
While not exactly a new environment for JavaScript to run with, desktop applications are a segment that ripe for growth as additional runtimes and libraries mature. The most popular solution for building desktop applications is Electron. Like similar frameworks, when developing applications for Electron, you will be using native web technologies that end up being wrapped in a native-focused container for any target desktop operating system.
Electron apps can target Apple macOS, Microsoft Windows, or Linux, and are all built-in JavaScript:

Figure 2.22: Electron—JavaScript on the desktop
The benefits of using a desktop-focused JavaScript runtime include the following:
- The ability to use native web technologies to write desktop applications.
- Most functionality is platform-agnostic, so, often, no specific operating system commands are needed.
You can learn more about Electron at https://electronjs.org/.
Mobile JavaScript
Mobile devices have been huge since iPhone and Android first made their debuts nearly a decade ago. Of course, developers want to tap into this segment of the market and, thankfully, there have been a lot of pretty good solutions over the years that make use of JavaScript. For quite some time, Apache Cordova and Adobe PhoneGap were the primary frameworks that were used to translate web technologies into functional mobile applications. More recently, technologies such as Ionic have become incredibly popular for those using common JavaScript-based frameworks such as Angular, React, and Vue. With many of these tools, you can also use plain vanilla JavaScript as well:

Figure 2.23: Ionic—JavaScript on mobile devices
The benefits of using a mobile-focused JavaScript runtime include the following:
- The ability to use native web technologies to write iOS and Android applications.
- Most functionality is platform-agnostic, so, often, no specific mobile operating system commands are needed.
You can learn more about Ionic at https://ionicframework.com/.
So far, we've had a brief overview of the various primary runtime environments for modern JavaScript.
In the next section, we'll focus once more on the web browsers that we introduced in the first chapter while paying more attention to the specific functions of some of the more useful views within their tools.