JavaScript basics: what the language is and where it is used

What JavaScript is

JavaScript is the language of the web browser. A script arrives as plain text, the browser runs it as it is, and the page can change in place: a click adds a class, a timer redraws a list, a fetch fills a table. Nothing is compiled and nothing is installed first.

Brendan Eich wrote the first version at Netscape in 1995, in about ten days. The standard is called ECMAScript, and a new edition appears every year; ES2015, also called ES6, brought the syntax most code uses today: let and const, arrow functions, classes, promises and modules.

The language is dynamic: a variable can hold a number now and a string later, and a function is an ordinary value that can be passed around. That flexibility is the point, and it is also the source of most bugs, so the later lessons spend time on types, scope and errors.

Where it runs

Every modern browser ships a JavaScript engine: Chrome and Edge run V8, Firefox runs SpiderMonkey, Safari runs JavaScriptCore. The same engines run outside the browser through Node.js, Deno and Bun, so one language covers the page, the server, the build script and the command line tool.

In the browser a script gets the DOM: the tree of elements of the page, with events and styles. Outside it there is no DOM, but there are files, network sockets and environment variables. Frameworks such as React, Vue and Express are libraries on top of that base, not a separate language.

The console first

The fastest place to try a line is the developer console of the browser: press F12 or Ctrl+Shift+I and open the Console tab. Type a line, press Enter, and the result appears under it. console.log prints a value and returns undefined, which is the console telling you the call itself produced nothing:

console.log("Hello, JavaScript");

Hello, JavaScript

The console keeps the history of the session, so it is also a calculator and a way to inspect the page: document.title prints the title of the open page, and document.querySelector finds an element.

A file and a page

Real code lives in a file. Save this line as hello.js and load the file at the end of the body of an HTML page, so that the elements above it already exist:

console.log("Hello, JavaScript");

<script src="hello.js"></script>

The same file runs in the terminal with Node, which is how the course runs the lessons that do not need a page:

node hello.js

Hello, JavaScript

A browser caches scripts, so a change that does not appear is usually an old copy: reload with Ctrl+F5 before looking for a bug in the code.

The course

The JavaScript course starts with this first line and continues lesson by lesson: syntax, variables, operators, conditions, loops, functions, objects, arrays, strings, the DOM and events, then promises, async and await, and the frameworks and tooling of a modern front end. Every lesson ends with a link to the next one.

The output on this page comes from the console of a desktop browser and from Node 20.11.0 (x86-64). A newer runtime prints its own version, and the Hello, JavaScript line is the same everywhere.

Article author: Arthur Isaev