Coding Hub  /  Start here

your first program

Write a file, save it, run it, and understand every step. Do it in both languages — the ideas are identical and the differences are worth seeing.

The three steps

Every program you ever write follows them.

01 Write, save, run

Programming has a loop at the centre of it, and it never changes however complicated the project gets.

  • Write instructions into a plain text file.
  • Save it, with the extension that says which language it is.
  • Run it, and read what comes back — including the errors.

The extension is not decoration. .py tells your computer to hand the file to Python; .js hands it to Node. Save a Python file as .txt and nothing will run it.

Word processors are not text editors. A file saved from Word carries invisible formatting that no language can read. Use VS Code.

the file extension decides
ExtensionRun it withRuns where
.pypython hello.pyYour terminal
.jsnode hello.jsYour terminal
.htmlOpen it in a browserThe browser

Python

The shorter of the two.

02 Hello in Python

Make a folder, open it in VS Code, and create a file called hello.py. Type this in — do not paste it. Typing it is how your fingers learn the punctuation.

print is a function. The brackets hold what you want to show, and the quotes mark where the text starts and stops.

hello.py
# Everything after a # is a comment. Python ignores it.
print("Hello, world!")

name = input("What is your name? ")
print("Nice to meet you,", name)

03 Running it

Open the terminal in VS Code with Ctrl+`. It starts in your project folder, which is why opening the folder mattered.

Type the command and press Enter. The output appears directly underneath.

On some systems the command is python3 rather than python. Try python --version first: if it reports a version starting with 3, you are set.

Terminal
python hello.py

04 What can go wrong

Four errors, and each one names its own cause once you can read it.

first-run errors
MessageMeans
can't open file 'hello.py'The terminal is in a different folder from the file. Check with ls (or dir).
SyntaxError: unterminated string literalA quote is missing its partner.
NameError: name 'print' is not definedA typo — Print or pint. Python is case-sensitive.
python: command not foundPython is not installed, or not on your PATH.

JavaScript

Same three steps, different runner.

05 Hello in JavaScript

Create hello.js in the same folder. The shape is the same: a function that prints, and some text in quotes.

The differences you can see straight away are that the printing function is called console.log, comments start with //, and lines may end with a semicolon.

hello.js
// Everything after // is a comment. JavaScript ignores it.
console.log("Hello, world!")

const name = "Ada"
console.log("Nice to meet you,", name)

06 Running it

Node is the program that runs JavaScript outside a browser. Same terminal, same shape of command.

JavaScript also runs inside a web page, which is the other way you will meet it. There, console.log prints to the browser's console rather than your terminal — open it with F12.

Terminal
node hello.js

07 The two side by side

The same program in both languages. Nearly everything that looks different here is punctuation, not meaning.

Notice what Python does not need: no braces, no semicolons, no keyword to make a variable. Indentation does the job the braces do in JavaScript — which is why indentation is not optional in Python.

hello.py
name = "Ada"
age = 36

if age >= 18:
    print(name, "is an adult")
else:
    print(name, "is a minor")
hello.js
const name = "Ada"
const age = 36

if (age >= 18) {
  console.log(name, "is an adult")
} else {
  console.log(name, "is a minor")
}

08 Now change something

Reading a working program teaches you very little. Breaking one teaches you a lot. Try each of these and read what comes back before you fix it.

The goal is not to avoid errors. It is to stop being surprised by them.

five things to try