Skip to the workspace
Pebellslearn by building
Introduction to JavaScript  ›  Lesson

What is JavaScript?

Introduction to JavaScript 10 min

Set up JavaScript and run your first file

A browser already contains a JavaScript engine. Install Node.js as well so you can run saved .js files from your terminal. We will use a one-line program before adding web-page behavior.

Already set up? Continue to the lesson

New to coding? Meet the tools and find the terminal
Browser
Runs JavaScript associated with a web page and provides the document and window APIs.
Node.js
Runs JavaScript files outside the browser.
npm
Installs JavaScript packages. No packages are needed for this first file.

A terminal is a window for commands. Its shell interprets those commands. PATH is the list of folders the shell searches for programs. An editor extension adds editing help; it usually does not install the language itself.

In VS Code, open your project folder, then choose View → Terminal. Type at the cursor in the Terminal panel, not in Output, the source file, or the browser address bar. Our command blocks omit prompt symbols such as $ and >; do not add them.

Official VS Code screenshot: the Terminal tab is selected below the editor, with the PowerShell shell name at the right and a command prompt at the left.
Find the Terminal tab and shell name. Open full-size screenshot (new tab).

The dropdown next to the plus button selects a shell. Choose the shell named in your operating-system instructions below. Available choices depend on what you installed.

Official VS Code screenshot: the arrow beside the terminal plus button opens a list containing PowerShell, Command Prompt, Git Bash and Ubuntu WSL.
Official documentation screenshots by Microsoft, VS Code terminal guide, CC BY 3.0 US. Unmodified; your version may look different.

Choose a system to see its installation steps. A computer is needed for these local setup instructions.

Official documentation and illustrated guides

Instructions reviewed 2026-10-27. Use the linked installer page for current versions and supported operating systems.

Continue to the lesson

javascript / What is JavaScript?

Explore each scene at your own pace.

01 · What is JavaScript?

What is JavaScript?

What is JavaScript?

JavaScript is the programming language that gives web pages behaviour, alongside HTML for structure and CSS for looks, and it also runs outside browsers.

A button can be visible and nicely styled without knowing what to do when you click it. JavaScript can supply those instructions.

Your goal: Make a blog button respond to a click, then explain why changing its color cannot repair a missing click handler.

Structure, style and functionality

A website's visible interface has three parts working together: structure, style and functionality. We use HTML to create the structure, CSS to style it, and JavaScript to add instructions for functionality.

Start with the layered illustration below. Each layer shows a different responsibility for the same page. Select a part to highlight it, then choose Combine layers to see how they fit together.

One interface · three responsibilities
An exploded three-dimensional view of a pageHTML supplies the heading, text and button. CSS supplies their colors, sizes and spacing. JavaScript connects a click to a label change. The same elements line up across all three layers.HTML · STRUCTUREA little space to think.Save articleCSS · STYLEA little space to think.Save articlespacing + colorJAVASCRIPT · FUNCTIONALITYClickSaved ✓Run instructions → change the labelsame buttonThe same page, separated to show each part
HTML creates the structure. CSS gives it style. JavaScript adds instructions for functionality. These work together in one interface.

Some interactions work through HTML alone, and CSS can also create animations. Here, JavaScript supplies the custom Save response.

Try the mechanism

Now try it on a blog

Choose a prediction, test it on the blog, then explain the result.

Field Notes / articleHTML only

After testing: what changed, and what stayed the same? Use that observation to explain your prediction.

Changing stages or removing/restoring CSS restarts this example. Saved state is temporary and is not stored in your account. The illustration has its own colors even without the card's CSS.

Make one change yourself

The example below isolates the save button so you can see every instruction. It changes a label only; it does not store an article.

Read it in this order:

  1. <button id="save"> creates the button and gives it a name we can find.
  2. document.querySelector("#save") finds that button. button is the name we use for it in the following lines.
  3. addEventListener("click", ...) registers instructions to run when a click happens. Registering them does not click the button.
  4. button.textContent = "Saved" replaces its displayed words when those instructions run.

You do not need to write the event-handler syntax from memory yet. First connect each instruction to an observable result.

Predict: If you change only "Saved" to "Added to my reading list", what will the button say before the first click? What will it say after?

html

Try it: Change the quoted message, update the preview, then click the button. Before the click, HTML still supplies Save article. After the click, the handler supplies your new message.

Break it deliberately: Remove just button.textContent = "...";, leaving the surrounding lines in place. Update the preview and click again. The button still exists; its click handler now has no instruction that changes the label. Put the line back and test your repair.

quick drill

You changed the button's background color, but its missing save handler is still missing. What should you expect?

quick drill

You removed the blog's CSS but kept its HTML and working click handler. What should still happen?

A changed label is not proof of storage

Our demo changes the visible words and keeps temporary state. It does not send anything to a server or restore a saved article after reloading. A real reading-list feature needs a place to store the saved item as well as this interface response.

JavaScript can also run outside web pages, for example in Node.js. This lesson uses a browser because you can directly observe what a click changes.

Output and page changes are different

console.log sends a message to the console or output panel. It does not find a button or change its label.

javascript

Change the message inside the quotes and run it again. Notice where the new text appears. The quotes mark a text value; they are not part of the printed message.

quick drill

You run console.log("Article saved"). What has that instruction demonstrated?

quick drill

In the small HTML preview, when does the instruction inside the click handler change the button text?

Check your understanding

Use the explanation exercise below to diagnose a blog button that looks correct but does not respond. Give a reason and a way to check your repair, rather than just naming a language.

Then write your own console message in the coding exercise. Keep the distinction clear: printed output, a changed interface, and stored data are three different results.

Scene 1 of 2
Project context and further resources
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.