TOC
About JavaScript:

JavaScript and the webbrowser

For many people, JavaScript and a webbrowser are very closely related. And that makes sense, since JavaScript was originally created by the team behind the Netscape Navigator webbrowser and solely used on the web. This is also why JavaScript is often referred to as a "safe language", because in its most common implementation, it never provides access to the underlying filesystem or anything like that - instead, it's more like a sandbox where you can do "good", non-system related things.

However, it's important to note that JavaScript can easily be used outside the webbrowser. JavaScript uses a JavaScript engine, or interpreter, to be executed. This engine can run inside a browser, and it does in pretty much every modern webbrowser known to mankind, but nothing prevents this engine to run outside of a browser. In fact, this has been done many times.

Node.js

The most notable example of this is the Node.js project. Created in 2009, it basically pulled the JavaScript engine out of the webbrowser and added modules to make JavaScript an all-purpose programming language instead of a webbrowser scripting language. This sparked a new and much higher level of interest in JavaScript, because now you could use your JavaScript skills for both the web (clientside) and for doing serverside scripts. And since Node.js is cross-platform, this suddenly allowed you to run your code across Windows, Linux, Unix, and macOS, without needing a browser.

The host environment

All of this leads us to the discussion of the host environment. The host environment is where your JavaScript is executed, and usually it includes functionality not directly found in the JavaScript language. The most obvious example of this is of course the webbrowser, which adds a LOT of functionality, allowing your JavaScript code to communicate with the browser and manipulate the contents of the underlying website.

Another hosting environment could be Node.js, adding serverside related functionality, but since JavaScript was originally designed to be able to run anywhere, this could also be your coffee machine. It could easily include a JavaScript engine and add functionality related to making coffee and taking instructions from push buttons instead of a website.

With or without a browser?

So, as you can see, JavaScript can definitely run outside the webbrowser. That's true now, and I can only imagine that the increasing popularity of JavaScript will make this even more true in the future. Therefore, it's important for me to stress that in this tutorial, we will first and foremost learn the JavaScript language.

So, in the first part of this tutorial, we will focus on the actual language and not talk too much about how it can interact with a browser. With that in mind, it would be silly to completely ignore how JavaScript interacts with the webbrowser since this is still such a common use case. Therefore, the latter part of this tutorial will be dedicated to exactly this subject, where we will dig deeper into the ties between JavaScript and the webbrowser.

A little heads-up to the purists out there: You might notice that even though we keep the browser out of the equation during the first part of the tutorial, I will be using a couple of functions which could be considered browser related. An example of this is the alert() function, which will show a simple message box in the browser. I use it because it's simple and easy to understand in the examples we use in this tutorial, and because it produces a result which can be seen when reading the tutorial in a webbrowser and running the examples directly from the website.

Summary

JavaScript is often run inside a webbrowser, but not always. In this tutorial we will focus on the core JavaScript language first, allowing you to learn the language, and then later on, we will look into how JavaScript can interact with a webbrowser. However, we will be showing you examples where we interact a bit with the browser, simply because it's easy to understand and can be tested while you read the articles.


This article has been fully translated into the following languages: Is your preferred language not on the list? Click here to help us translate this article into your language!