The language every browser speaks
Open any web page and the chances are that JavaScript is running on it: it opens menus, checks a form before you send it, draws a map you can drag, or updates the score of a match without reloading the page. Every mainstream browser, on every phone, tablet and laptop, ships with a JavaScript engine built in. No other programming language is installed on so many devices.
It no longer stays in the browser. The same language runs web servers, command-line tools, the build systems that package other software, desktop applications such as code editors, and serverless functions in the cloud. Teams often choose it so that one language serves both the page a user sees and the server that answers it.
This course teaches the language as professionals write it today. In this first lesson you will meet its history and design, see where it runs, install a runtime, and run your first programs. You already know what a variable, a loop and a function are; here you will see how JavaScript spells them, and from the next lesson on, where it surprises people.
Ten days in 1995, and thirty years since
In May 1995 Brendan Eich, newly hired at Netscape Communications, was asked to create a scripting language for the Netscape Navigator browser. Netscape wanted something easy enough for designers and hobbyists to paste into a page, and it wanted it fast: the first prototype took about ten days. The language was called Mocha, then LiveScript, and was renamed JavaScript in December 1995 as part of a marketing agreement with Sun Microsystems, whose Java language was then the most talked-about thing in software. The two languages are unrelated apart from some syntax and that marketing decision.
Eich drew on three sources, and you can still see all of them:
- Java lent the look: curly braces,
if,for,while, semicolons. Management asked for that. - Scheme, a Lisp dialect, lent the heart: functions are values you can store, pass and return, and they remember the variables around them (closures, in lesson four).
- Self, a research language, lent prototypes: objects inherit directly from other objects, with no classes needed (lesson five).
Microsoft shipped its own compatible version, JScript, in 1996. To stop the language splitting in two, Netscape handed it to Ecma International, a standards body, and the first edition of the standard, ECMA-262, appeared in June 1997. The standard calls the language ECMAScript, because "JavaScript" is a trademark (now held by Oracle). In practice everyone says JavaScript and means ECMAScript plus whatever the browser or server adds.
The standard then moved in fits and starts. The third edition (1999) lasted a decade; an ambitious fourth edition was abandoned in 2008; the fifth (2009) added strict mode and built-in JSON support. The sixth, ECMAScript 2015 (often called ES6), was the great modernisation: let and const, arrow functions, classes, modules, promises, destructuring and much more. Since then the committee that maintains the language, TC39, has published a new edition every June, named after its year. This course targets ECMAScript 2025, the sixteenth edition.
TC39 works in public. A new feature starts as a proposal and passes through numbered stages: an idea, a design, a specification text, implementations in real engines, and finally, at stage 4, inclusion in the next yearly edition. You can follow every proposal on GitHub.
One principle explains much of what is odd about JavaScript: don't break the web. Billions of pages written over thirty years must keep working, so mistakes in the language can almost never be removed. Instead, better alternatives are added beside them: let beside var, === beside ==, modules beside global scripts. A large part of learning modern JavaScript is learning which half of each pair to use. This course will always tell you.
Engines, hosts and runtimes
Two words help you understand where JavaScript runs.
Definition— engine
A JavaScript engine is the program that reads JavaScript source code and executes it. The main ones are V8 (in Chrome, Edge, Node.js and Deno), SpiderMonkey (in Firefox) and JavaScriptCore (in Safari and Bun). Modern engines compile hot code to machine code while the program runs (just-in-time compilation), which is why JavaScript is far faster than its reputation from the early 2000s.
Definition— host and runtime
An engine alone can only compute. The host is the environment that embeds the engine and gives the program a way to touch the world: a page to draw on, files to read, a network to talk to, timers. A runtime is an engine plus such a host, packaged so you can run programs.
The ECMAScript standard defines the language and its built-in objects, such as Math, JSON, Array, Map and Promise. Everything else comes from the host. Surprisingly, that includes console.log and setTimeout: they are so universal that they feel like part of the language, but each host provides its own.
| Runtime | First released | Engine | What the host adds | Typical use |
|---|---|---|---|---|
| Web browsers | 1995 | V8, SpiderMonkey, JavaScriptCore | the page (the DOM), events, fetch, storage, graphics | interactive web pages and web apps |
| Node.js | 2009 | V8 | files, processes, network servers, npm packages | servers, tools, build systems |
| Deno | 2020 (1.0) | V8 | Node-compatible APIs, built-in TypeScript, permissions | servers and scripts with a security sandbox |
| Bun | 2023 (1.0) | JavaScriptCore | Node-compatible APIs, a fast package manager and bundler | the same jobs as Node, with an emphasis on speed |
Node.js, created by Ryan Dahl, is by far the most used outside the browser, and it is what this course runs on. Dahl later started Deno to fix design choices in Node he had come to regret, such as its unrestricted access to files and network by default. Bun is a newer, independently built runtime aiming at speed and drop-in compatibility with Node. A program that sticks to the language and to standard web APIs (fetch, URL, setTimeout, TextEncoder) usually runs unchanged on all of them.
Analogy, not a formal construction
Think of the engine as a musician and the host as the venue. The same violinist can play in a concert hall, a church or a street; the music (the language) is the same, but what is available (a piano, a choir, an audience walking past) depends on where they are.
Installing Node.js and running a program
Download the current LTS (long-term support) release from nodejs.org. The site offers an installer for Windows and macOS and instructions for Linux, and it also describes version managers such as nvm and fnm. Professionals usually use a version manager, because different projects need different Node versions, and it lets you switch with one command. Either way, check the installation from a terminal:
node --version
npm --versionThe first prints the Node version (something like v22.14.0; any LTS release from 22 onward runs everything in this course). The second is npm, Node's package manager, which you will use in the last lesson.
The interactive prompt
Type node with nothing after it and you get a REPL (read–eval–print loop): type an expression, press Enter, see its value. It is the quickest way to answer "what does this do?".
> 7 * 6
42
> "Lumen" + "ary"
'Lumenary'
> Math.max(3, 9, 4)
9Leave it with .exit or by pressing Ctrl+D (Ctrl+C twice also works).
Your first program
Create a file called hello.mjs with any text editor (Visual Studio Code is the most common choice among JavaScript developers, and it is free), type this program, save it, and run node hello.mjs in the same folder:
// hello.mjs: your first JavaScript program
console.log("Hello, world!");
const learner = "Amara";
const year = 2026;
console.log(`Welcome, ${learner}. JavaScript is ${year - 1995} years old.`);It prints:
Hello, world!
Welcome, Amara. JavaScript is 31 years old.Line by line:
//starts a comment that runs to the end of the line. (/* ... */comments can span several lines.)console.log(...)writes its arguments to the terminal, followed by a newline. In a browser it writes to the developer console.const learner = "Amara";creates a constant: a name bound to a value that cannot be reassigned. The next lesson coversconstandlet.- The text between backticks is a template literal. Inside it,
${...}holds any expression; its value is inserted into the text. Here${year - 1995}becomes31. Plain strings use"double"or'single'quotes, which mean the same thing.
Why .mjs?
JavaScript has two ways to organise code into files. The modern, standard one is ES modules (import and export), and it is what this course uses. Node also supports an older system of its own, CommonJS (require). A file ending in .mjs is always treated as an ES module. In a real project you would keep the .js extension and add "type": "module" to the project's package.json file instead, which has the same effect; lesson ten shows how. Modules also switch on strict mode automatically, which turns several silent mistakes into errors. That is another reason to prefer them.
Reading a real program
Here is a slightly longer program. Read it and guess what it prints before you look:
// Convert a week of noon temperatures from Celsius to Fahrenheit.
const city = "Nairobi";
const celsius = [24, 26, 25, 23, 27, 28, 26];
let total = 0;
for (const c of celsius) {
const f = c * 9 / 5 + 32;
console.log(`${c} °C is ${f.toFixed(1)} °F`);
total += c;
}
const average = total / celsius.length;
console.log(`Average in ${city}: ${average.toFixed(2)} °C`);24 °C is 75.2 °F
26 °C is 78.8 °F
25 °C is 77.0 °F
23 °C is 73.4 °F
27 °C is 80.6 °F
28 °C is 82.4 °F
26 °C is 78.8 °F
Average in Nairobi: 25.57 °CA few things to notice, all covered properly in the coming lessons:
[24, 26, ...]is an array, JavaScript's ordered list.celsius.lengthis its number of elements.for (const c of celsius)visits each element in turn. Theconstis fresh on each pass through the loop, so it can be a constant even though it takes a new value every time.let total = 0is a variable that can change;total += cadds to it.- There is only one kind of number for both
24and75.2: a 64-bit floating-point number.f.toFixed(1)turns a number into a string with exactly one digit after the decimal point. - Statements end with semicolons. JavaScript will insert most missing semicolons for you (a rule called automatic semicolon insertion), and some teams omit them on purpose. This course writes them, which is the more common style and avoids a few rare traps.
- Text is Unicode, so
°Cand names in any script work as you would hope.
What belongs to the language, and what to the host
You can ask any value for its type with the typeof operator. This program uses it to find out which objects exist where it is running:
// The language is the same everywhere; the host's objects are not.
console.log("typeof globalThis:", typeof globalThis);
console.log("typeof Math.max:", typeof Math.max); // part of ECMAScript
console.log("typeof process:", typeof process); // provided by Node
console.log("typeof document:", typeof document); // provided by browsers only
if (typeof document === "undefined") {
console.log("No web page here: this is a server-side runtime.");
}
console.log("Is this file a module?", typeof require === "undefined");
console.log("Module URL ends with:", import.meta.url.split("/").pop());typeof globalThis: object
typeof Math.max: function
typeof process: object
typeof document: undefined
No web page here: this is a server-side runtime.
Is this file a module? true
Module URL ends with: main.mjsWhen console.log gets several arguments, it prints them separated by spaces. globalThis is the standard name for the global object in every host. process describes the running Node process; document is the web page, which a server does not have. In an ES module, CommonJS's require does not exist, and import.meta.url tells a module where its own file lives. (The test suite saved this program as main.mjs, which is why that name appears.)
JavaScript in the browser
Every desktop browser has developer tools. Open them with F12 (or Cmd+Option+J in Chrome on a Mac, Cmd+Option+I in Safari after enabling its Develop menu) and choose the Console tab: it is a REPL connected to the page you are looking at. Try typing these, one at a time, on any page:
document.title
document.querySelectorAll("a").length
document.body.style.background = "lightyellow"The first shows the page's title; the second counts its links; the third paints the page yellow until you reload. None of these works in Node, because document exists only where there is a page. That is why the lessons show browser code in plain blocks like this one and explain it, while every program you can run with node is checked and shown with its real output.
A web page loads JavaScript with a script element in its HTML. The modern form is:
<script type="module" src="app.js"></script>type="module" makes the file an ES module, exactly like our .mjs files, and also delays running it until the page has been read. Lesson nine is about the browser in detail.
Common misconceptions
Misconception
"JavaScript is a simpler version of Java." They are different languages with different designs, from different companies. Java is statically typed, class-based and compiled ahead of time to bytecode; JavaScript is dynamically typed, prototype-based and was designed for scripting pages. The shared name was a 1995 marketing decision.
Misconception
"JavaScript is interpreted, so it is slow." Engines interpret code at first and then compile the frequently used parts to optimised machine code as the program runs. For typical application code, modern JavaScript is fast; it will not match carefully written C or Rust on heavy numerical work, which is why browsers also run WebAssembly for such jobs.
Misconception
"console.log is part of JavaScript." It is provided by the host. Every browser and server runtime has it, so in practice you can rely on it, but it is not in the ECMAScript standard, and its exact formatting differs between hosts. (Node prints 'Lumenary' in the REPL with quotes; a browser console shows strings in its own way.)
Misconception
"I need to learn old JavaScript first." You will meet var, == and callback-heavy code in older projects, and these lessons explain them when they come up. But start with the modern language: it is simpler, safer and what new code is written in.
Exercises
Try each one in your head first, then check it with node.
1. First steps
Warm-upHumanWho decides what goes into the JavaScript language today?
2. First steps
Warm-upComputationalWhat does this program print?
const name = "Kofi";
const apples = 3;
console.log("Hi", name, `you have ${apples * 4} apples`);
3. First steps
Warm-upComputationalWhat number does this program print?
let steps = 0;
for (const n of [3, 1, 4, 1, 5]) {
steps += n;
}
console.log(steps * 2);
4. First steps
CoreHumanWhich of these are provided by the host (the browser or Node.js) rather than defined by the ECMAScript standard? Give every one that applies.
console, Math, setTimeout, JSON, document, Promise, process
5. First steps
CoreComputationalRun in Node as an ES module, what does this print?
console.log(typeof console, typeof setTimeout, typeof JSON, typeof Math);
6. First steps
CoreHumanWhy do the programs in this course use the .mjs extension when run with Node?
7. First steps
StretchHumanJavaScript has both var and let, both == and ===. Why does the language keep the older, more error-prone form of each?
Further reading and resources
- MDN: JavaScript Guide · Mozilla and contributorsA thorough, free guide to the language, kept up to date.
- Download Node.js · OpenJS FoundationInstallers and version managers for every operating system.
- ECMAScript Language Specification · Ecma TC39The standard itself. Not a tutorial, but worth knowing it exists.
- JavaScript: the first 20 years · Allen Wirfs-Brock and Brendan Eich · 2020The definitive history, written for the ACM History of Programming Languages conference by two people who shaped it.
- Deno
- Bun