Code Literacy

Unit 4 · Thinking like a programmer

let vs const in JavaScript

Use const for a box you fill once and never refill. Use let for a value that will change, such as a counter. Reassigning a const throws an error.

The mix-up

What people often think

“const and let are the same kind of box.”

What the tutor says

A const box is sealed once filled, so refilling it is an error. Use let for a value that changes.

How it works

Defaulting to const is a good habit: when you see let, you know the value is meant to change, and an accidental reassignment of a const is caught straight away.

const seals the box, not necessarily what is inside it. A const array can still have items pushed into it; you just cannot replace it with a different array.

Side by side

The mix-upJavaScript
const visits = 0;
visits = visits + 1;  // TypeError: Assignment to constant variable
A const cannot be refilled.
What worksJavaScript
let visits = 0;
visits = visits + 1;
let for values that change.

Practise it with a tutor watching

Variables are labelled boxes

Store values in variables, update them, and tell assigning apart from comparing.

15 minutes See it Build it Break it Say it
Start the lesson

Free with an account. The first two units need no account.

© 2026 webfaCeMEdia. Code Literacy™ is a trademark of webfaCeMEdia.