First steps: programs, values and variables · Part 1 of 36

What is a program?

Basic 10 min

A program is a precise list of instructions. See how source code becomes behaviour and run your first line of code.

What you will learn

  • You can explain what a program, source code and a runtime are.
  • You can tell a syntax error from a logic error.
  • You can run and change a one-line program in JavaScript and Python.

Instructions, very precisely

A program is a list of instructions that a computer follows exactly. "Exactly" is the important word: the computer does not guess what you meant. If a recipe says "add salt", a cook knows roughly how much. A computer needs "add 5 grams of salt", and if you wrote "add 5 kilograms" it would do that too, without complaint.

The text you write is called source code. It is plain text in a programming language — a small, strict language with a fixed vocabulary and grammar. A separate program then runs it:

  • JavaScript runs in every web browser and, on servers, in runtimes such as Node.js. The browser's engine reads your code, turns it into machine instructions while it runs, and executes them.
  • Python is usually run by the CPython interpreter, which first translates your file into compact bytecode and then executes that bytecode step by step.

You never need to write machine code yourself; that is exactly what these tools do for you.

A recipe card-like sheet of simple step icons next to a small robot cook

Your first line

Here is the classic first program in both languages:

// JavaScript
console.log("Hello, world!");
# Python
print("Hello, world!")

Both lines ask the runtime to show a piece of text. console.log and print are functions that somebody already wrote for you; the parentheses hand them the value to show. The quotes mark the text as a string — data, not instructions. Lines starting with // (JavaScript) or # (Python) are comments: notes for humans that the computer ignores.

Try it: JavaScript sandbox

Write and run small JavaScript programs; the checker tells you when an exercise is solved.

Turn on JavaScript to use this lab. Worked example:

The sandbox runs JavaScript in a separate worker without network access. Exercise 1 asks you to print exactly Hello, world!. Typing console.log("Hello, world!") and pressing Run shows the text in the output panel and marks the exercise as solved.

Two kinds of mistakes

You will make mistakes all the time — every programmer does, every day. They come in two main kinds:

  1. Syntax errors. The code breaks the grammar of the language, for example a missing closing quote: print("Hello). The runtime refuses to start and tells you roughly where the problem is. Read the message slowly: the line number is often right, or the mistake is just before it.
  2. Logic errors (bugs). The code is valid, runs, and does the wrong thing — for example it adds where it should multiply. No error message helps you here. You find them by testing: you predict what the program should print, run it, and compare.

There is a third kind, runtime errors, where valid code fails while running, for example because it tries to divide by zero in Python or reads a property of undefined in JavaScript.

A flow from source code through the runtime to output, with syntax and runtime errors branching off
From source code to output

How programmers actually work

Programming is a loop: write a little, run it, look at the result, change something. Small steps win. If you write 100 lines before running anything, a mistake can hide anywhere in them; if you run after every three lines, you know where it is.

Good habits from day one:

  • Give things clear names (price_per_kg, not x).
  • Run your code often.
  • Read error messages completely, including the line number.
  • Keep a copy of code that works before you change a lot.

Key points

  • A program is a precise list of instructions; the computer does exactly what it says.
  • Source code is plain text; a runtime (browser engine, Node.js, CPython) executes it.
  • console.log(...) in JavaScript and print(...) in Python show a value.
  • Syntax errors stop the program from starting; logic errors make it do the wrong thing.
  • Work in small steps: write a little, run it, compare with what you expected.

Flashcards

Question: What is source code?
Answer: The plain-text instructions you write in a programming language.
Question: How do you print text in JavaScript and in Python?
Answer: console.log("text") in JavaScript, print("text") in Python.
Question: What is the difference between a syntax error and a logic error?
Answer: A syntax error breaks the language's grammar so the code won't run; a logic error runs but gives the wrong result.
Question: What does a comment do?
Answer: Nothing for the computer — it is a note for humans (// in JavaScript, # in Python).

Check yourself

Think about your answer, then open it. In the app the quiz is interactive, earns points and brings back what you missed.

  1. What does a runtime such as Node.js or CPython do?

    • It executes your source code
    • It checks your spelling in comments
    • It draws the user interface of your editor
    • It stores your files in the cloud
    Show the answer

    It executes your source code

    A runtime reads the source code and executes it; Node.js runs JavaScript, CPython runs Python.

    Source: The Python Tutorial, ch. 2

  2. `print("Hello)` fails before anything runs. What kind of error is this?

    • Syntax error
    • Logic error
    • Network error
    • Rounding error
    Show the answer

    Syntax error

    The closing quote is missing, so the code breaks the grammar of the language — a syntax error.

    Source: The Python Tutorial, ch. 8 Errors and Exceptions

  3. Which lines are comments?

    • // total price
    • # total price
    • print("# total price")
    • console.log("// total")
    Show the answer

    // total price; # total price

    // starts a comment in JavaScript and # in Python. Inside quotes the characters are part of a string, not comments.

    Source: MDN JavaScript Guide, Grammar and types

  4. In JavaScript you show a value with console.___("Hi").

    Show the answer

    log

    console.log() writes a message to the console.

    Source: MDN Web Docs, console.log()

Sources

Facts checked on 2026-11-30. Skillgrove lessons are free learning material — no certificate and no accreditation.