Programs, values, and types · Lesson 1 of 77 · concept

What a program actually is

About 40 minutes.

By the end of this lesson you can

  • Say what a program is in one plain sentence, without using the word code.
  • Point at the value, the expression and the statement in a line of JavaScript.
  • Read a two-line program and say what it does before you run it.
  • Write a one-line program that puts a value on the screen.

A program is a list of instructions, in order

Explanation

A program is a list of instructions, written down in advance, that a machine carries out one at a time from the top of the list to the bottom. That is the whole idea. Everything else you will learn in this course — the punctuation, the words, the names — is about writing those instructions down clearly enough that there is only one way to read them.

Nothing about that is unique to computers. A fire drill notice is a list of instructions. So is a knitting pattern. What makes a computer program different is only who carries it out, and how literally.

JavaScript is one particular way of writing instructions down. It was created for web browsers, but you do not need a browser to use it, and you do not need one for this course: the code you write here runs in a small, sealed JavaScript engine built into this page. It cannot touch your files, your network or anything else. It is a safe place to be wrong in.

A recipe for a cook who never guesses

An analogy

Imagine writing a recipe for a cook who is fast, tireless, and completely literal. They will do exactly what you wrote, in the order you wrote it, at enormous speed. They will never think you probably meant something else.

Tell that cook "add the eggs" without saying how many, and they stop. Write "add teh eggs" and they stop, because they have never heard of teh. Write the steps in the wrong order and they will happily bake an empty tin, because you told them to.

This sounds like a weakness. It is the single most useful property a computer has. Because the machine never guesses, a program that worked yesterday works today, and when something goes wrong the cause is always in the instructions — which means it is always findable. Programming is not a talent for being right first time. It is the habit of reading what you actually wrote.

Three words you will use every day

Explanation

A VALUE is a single piece of information the program is holding right now: the number 7, the piece of text Hello, the answer true. Values are what programs are made of, the way sentences are made of words.

An EXPRESSION is any piece of code that produces a value. 7 is an expression — it produces 7. 2 + 3 is an expression too; it produces 5. The useful test is: could I replace this piece of code with a single value and have the program mean the same thing? If yes, it is an expression.

A STATEMENT is one complete instruction — one line of the recipe. In JavaScript most statements end with a semicolon, which marks the end of the instruction the way a full stop marks the end of a sentence. The line console.log("hi"); is a statement. The fragment 2 + 3 on its own is only an expression; put it inside an instruction and the whole line becomes a statement.

Expressions live inside statements. A statement says do this; the expressions inside it say with what. Once you can see which part of a line is which, unfamiliar code stops looking like noise.

How to read a line you have never seen

A mental model

Read every line inside-out. Find the innermost expressions first, work out what value each one produces, and mentally replace it with that value. Keep going until the whole line is one instruction with plain values in it. Then ask what the instruction does with them.

For the line console.log(2 + 3); that is two steps. Step one: 2 + 3 produces 5, so the line now reads console.log(5). Step two: console.log is the instruction "show this value", so the line shows 5.

This is exactly how the machine does it, and doing it by hand is how you will debug for the rest of your life. If you can predict a line before running it, you understand it. If you cannot, run it and find out — that is what the run button is for.

Why the fussiness is on your side

Why it matters

Beginners usually meet a computer's precision as an insult: one wrong character and nothing works. It helps to flip that around. The rules are small, fixed, and public. There are no secret rules, no rules that apply only to experts, and no rules that change on Tuesdays.

That means every error message you will ever get is a fact about your text, not a verdict about you. The gap between a beginner and a professional is not that the professional writes it correctly first time — they do not — it is that they read the message, look at the line, and fix it without taking it personally.

The mistakes everybody makes on day one

A common mistake

Capital letters matter. The names greeting and Greeting are two completely different names to JavaScript, in the same way that Sam and Pam are two different people. A great many day-one errors are exactly this.

Quotes must match, and they must be straight. Double quotes around a piece of text are fine and single quotes are fine, but you cannot open with one kind and close with the other — and the curved quotes a word processor inserts are not quotes at all as far as JavaScript is concerned. Write code in a code editor, never in a document.

Every opening bracket needs its closing partner. If you miss the closing one, the machine reads on looking for the end of your instruction and then complains about a line further down than the one you actually broke. When an error points at a line that looks fine, check the line above it.

None of these mistakes are dangerous. In this player the worst that happens is a red message and you try again.

Recap

Recap

A program is an ordered list of instructions carried out literally, one at a time. A value is a single piece of information. An expression is any code that produces a value. A statement is one complete instruction, usually ended with a semicolon. Read unfamiliar lines inside-out, replacing each expression with the value it produces.

Worked examples

Every output below was produced by actually running the code in the same sandbox your exercises run in — it is not a prediction.

A complete two-statement program

The smallest program worth writing: it makes a value, gives it a name, and shows it. Read it top to bottom, then read the notes on each line.

1const greeting = "Hello, world!";2console.log(greeting);
  • line 1

    One statement. It creates the text value Hello, world! and attaches the name greeting to it. The quotation marks are not part of the value — they only mark where the text starts and stops.

  • line 2

    A second statement, carried out after the first. console.log shows a value. Here the expression inside the brackets is the name greeting, which produces the value it was attached to.

What it prints

Hello, world!

The same characters can be a sum or a piece of text

Quotation marks change everything: with them JavaScript sees text and copies it out; without them it sees an expression and works out the answer.

1console.log(2 + 3);2console.log("2 + 3");
  • line 1

    No quotes, so 2 + 3 is an expression. It produces the value 5 before console.log ever sees it.

  • line 2

    Quotes, so this is a piece of text that happens to contain a plus sign. Nothing is added up; the characters are shown exactly as written.

What it prints

52 + 3

Check yourself

Not scored, not stored. Getting one wrong is the useful part.

In the statement const total = 2 + 3; which part is the expression that produces a value?

Two statements run in the order they are written. What appears, and in what order?

console.log("second thoughts");console.log(1 + 1);

A program declares const answer = 42; and then asks for console.log(Answer); What happens?

Write it yourself

Exercise · intro · 3 tests

Fix the greeting

The program below greets nobody in particular. Change the text so it greets the whole world. It must read exactly: Hello, world! — a capital H, a comma, one space, then world in lower case, then an exclamation mark. Change nothing else.

What your code must do

The constant named greeting holds the exact text Hello, world! with no leading or trailing spaces. The tests read the value of greeting; they cannot see the lines you printed, so print for your own benefit.

Define greeting at the top level of your code — the tests call it by name.

Runs on your device in a sandbox with no network and no access to this page.

Worth remembering

  • What is a program, in one sentence?

    An ordered list of instructions that a machine carries out literally, one at a time, from top to bottom.

  • What is the difference between an expression and a statement?

    An expression is any code that produces a value, so it could be replaced by that value. A statement is one complete instruction, usually ended with a semicolon. Expressions live inside statements.

Check this lesson against the source

We wrote the explanation; we did not invent the facts. This is the page that backs them.

MDN — JavaScript Guide: Introduction

Check there: The Hello world section, which shows a first complete JavaScript program made of statements.

MDN — JavaScript Guide: Grammar and types

Check there: That JavaScript is case-sensitive and that statements are separated by semicolons.

Prefer to read the source in a structured breakdown? Turn this doc into a breakdown

0 of 1 exercise in this lesson solved on this device

Consent version 2026-07-31.1

Cookie preferences