Lesson 27 of 296
What JavaScript is and where it runs
What you will learn
- What a programming language is
- What JavaScript is used for
- What an engine and a runtime are
- The difference between running JavaScript in a browser and in Node.js
- What ECMAScript is
- How to run your first line of JavaScript
On this page
What is a programming language?
A computer only understands very simple instructions. A programming language is a way to write instructions that people can read and that the computer can also follow. A list of instructions is called a program or code.
What is JavaScript?
JavaScript (often written JS) is a programming language. It was created in 1995 to make web pages interactive, for example to react when a user clicks a button. Today it is used for much more:
| Where | What it does |
|---|---|
| Web pages | Buttons, forms, menus, live updates (front end) |
| Servers | APIs, databases, logins (back end, with Node.js) |
| Mobile apps | With tools such as React Native |
| Desktop apps | With tools such as Electron |
JavaScript is not Java. They are two completely different languages. Only the names are similar, which was a marketing decision in 1995.
Engine
Code is only text. A program must read that text and carry out the instructions. The program that does this for JavaScript is called a JavaScript engine.
The most famous engine is V8, made by Google. It is used in the Chrome browser and in Node.js. Other browsers have their own engines: Firefox uses SpiderMonkey and Safari uses JavaScriptCore.
The engine understands only the JavaScript language itself: variables, maths, decisions, loops, functions.
Runtime
A runtime is the full environment where JavaScript runs. It is the engine plus extra features. The extra features decide what your code is allowed to do.
| Runtime | Engine | Extra features | Used for |
|---|---|---|---|
| Browser (Chrome) | V8 | Change the web page, react to clicks, store data in the browser, make network requests | Front end |
| Node.js | V8 | Read and write files, run a web server, connect to databases | Back end |
So the language is the same, but the features available are different. For example, document (the web page) exists in the browser but not in Node.js. fs (the file system) exists in Node.js but not in the browser.
ECMAScript
ECMAScript is the official rulebook (the "specification") for the JavaScript language. Engines follow this rulebook. New versions come out every year, named by year, such as ES2025. ES6 (also called ES2015) was a very big update that added let, const, arrow functions, classes and much more. When people say "modern JavaScript", they usually mean ES6 and later.
Is JavaScript compiled or interpreted?
Simple answer: both. Older engines read and ran code line by line (interpreting). Modern engines like V8 use JIT (Just-In-Time) compilation: they start running the code quickly, then turn the parts that run often into fast machine code while the program is running.
How to run JavaScript
1. In the browser console. Open dev tools (Lesson 4), click Console, type and press Enter:
console.log("Hello, world");2. In a web page. Put a <script> tag in an HTML file:
<script src="app.js" defer></script>3. With Node.js. Install Node.js, save code in a file such as app.js, then in the terminal:
node app.js4. In an online editor. Sites with a browser code editor let you write and run code without installing anything. This is useful on a phone or a borrowed computer.
Common mistakes
- Thinking JavaScript and Java are the same.
- Calling Node.js a language or an engine. It is a runtime.
- Trying to use
documentin Node.js, orfsin the browser.
How to say it in an interview
"JavaScript is a programming language that runs in browsers and, through Node.js, on servers. An engine such as V8 reads and executes the code. A runtime is the engine plus extra APIs: the browser adds the DOM and web APIs, while Node.js adds the file system and networking. The language itself is defined by the ECMAScript specification."
Key words
| Word | Meaning |
|---|---|
| Program / code | A list of instructions for the computer |
| JavaScript engine | The program that reads and runs JavaScript, such as V8 |
| Runtime | The engine plus extra features, such as a browser or Node.js |
| Node.js | A runtime that runs JavaScript outside the browser |
| ECMAScript | The official specification of the JavaScript language |
| ES6 | The 2015 version that added most modern features |
| JIT compilation | Turning code into fast machine code while it runs |
Now prove it
This lesson is complete when you pass the quiz and all three practice levels.