Introduction to JavaScript

JavaScript is the programming language of the web. HTML describes a page's structure and CSS its appearance; JavaScript describes its behaviour — what happens when someone clicks, types, scrolls or waits. Today it also runs servers, command-line tools, mobile apps and more.

What JavaScript does in a web page

Every modern browser contains a JavaScript engine. When a page loads a script, the engine runs it, and the script can then:

  • Change the page — add, remove or edit text, images and whole sections.
  • React to the user — clicks, key presses, form submissions, scrolling.
  • Talk to servers — load fresh data without reloading the page.
  • Remember things — store settings in the browser between visits.

Here's a tiny taste. Click the button in the result area, then change the message in the code and click again:

Try it yourself
Result

Don't worry about understanding every word yet — by lesson 44 you'll write code like this from scratch.

Your first line of code

console.log() prints a value. It's the tool you'll use most while learning, because it lets you see what your code is doing:

Try it yourself
Console output

The editors on this site show console output directly below the code. In a real browser, it appears in the developer tools, opened with F12 (or Cmd+Option+J on a Mac) — lesson 03 shows you around.

Where JavaScript runs

EnvironmentWhat it's used for
Browsers (Chrome, Firefox, Safari, Edge)Interactive web pages and web apps
Node.js, Deno, BunWeb servers, APIs, build tools and scripts
React Native, ElectronMobile and desktop apps
Databases and cloud functionsQueries, serverless code, automation

The core language is the same everywhere. What differs is what's available around it: browsers provide document and window for working with pages, while Node.js provides modules for files and networking.

JavaScript is not Java

Despite the name, JavaScript and Java are unrelated languages. The name was a marketing decision in 1995, when Java was fashionable. The official standard is called ECMAScript; new versions are published every year (ES2015, ES2016 and so on), and browsers adopt new features quickly. Lesson 59 covers the most useful modern additions.

How this course works

  • Each lesson builds on the previous ones, so it's best to go in order.
  • Examples show their output underneath. Examples marked Try it yourself are editable — change them and the output updates instantly.
  • Practice with the exercises and check your understanding with the quiz.
Tip: the fastest way to learn is to break things on purpose. Change a value, delete a bracket, misspell a name — and see what happens. Error messages are a normal, everyday part of programming, not a sign you're doing it wrong.