Chapters

Getting startedChapter 1 of 21

Introduction

What JavaScript is, where it runs, and what it is actually for.

What JavaScript is

JavaScript is the programming language browsers run. HTML describes what is on a page and CSS describes how it looks; JavaScript is what makes it do something. Click a button and see a menu open, type in a field and see it validated, scroll and see more results load: that is JavaScript.

It is not related to Java. The name was a marketing decision made in 1995 and it has confused people ever since.

Where it runs

Every browser has a JavaScript engine built in, so you need nothing installed to start. The same language also runs outside the browser on Node.js, which is how it ended up on servers, in build tools and in desktop apps.

This tutorial stays in the browser. Every example on the site runs in this tab.

JavaScriptif you read this after midday

JavaScript

const hour = new Date().getHours();
const part = hour < 12 ? 'morning' : 'afternoon';

console.log(`Good ${part}.`);

Output

Good afternoon.

What it is used for

  • Reacting to what someone does: clicks, typing, scrolling, submitting a form.
  • Changing the page after it has loaded, without asking the server for a new one.
  • Fetching data in the background and showing it when it arrives.
  • Holding state: what is in a basket, which tab is open, what has been typed but not saved.

What you need

A browser and somewhere to type. That is genuinely all. The examples here are editable and run on the page, so you can change one and see what happens immediately.

For your own work later, any text editor will do, and the browser's developer tools give you a console to try things in. Press F12 in most browsers to open it.

Note

This tutorial uses modern JavaScript throughout. Where an older form still appears in code you will meet elsewhere, it is called out as something to recognise rather than something to write.

How this tutorial works

One idea per chapter, in order, each a few minutes long. Every chapter ends with a short test, and most have exercises where you write the code yourself and get it checked.

Your progress is remembered in this browser. There is no account and nothing is sent anywhere.

Test yourself

2 questions

What is the relationship between JavaScript and Java?

Show the answer

They are unrelated languages with similar names The name came from a 1995 marketing arrangement, not from any shared design.

What do you need installed to run the JavaScript in this tutorial?

Show the answer

Nothing beyond a browser The engine is already in the browser, which is why the examples here run on the page.

Next chapter

Where To Put It

Script tags, external files, and what defer and async actually change.