By the end of this lesson
Choose const by default and let when a binding must change.
Before you start
- Node.js 24 with a terminal and plain-text editor; the browser-only lesson is labelled separately.
- Complete lesson 1 or be comfortable with its examples.
Three words to know
- Binding
- The connection between a name and a value.
- Reassignment
- Making an existing name refer to a different value.
- Block scope
- A name’s visibility within a pair of braces.
1. Give values useful names
const creates a binding that cannot be reassigned. let permits reassignment. Prefer descriptive camelCase names and use const unless a later assignment is part of the design. A declaration alone does not print a value.
const learnerName = "Sam";
let completed = 2;
completed += 1;
console.log(`${learnerName}: ${completed}`);
What you should see · example output
Sam: 3
2. A constant is not a frozen object
const protects the binding, not the contents of an array or object. The array can still be changed. A later lesson explains copying and shared references.
const topics = ["terminal"];
topics.push("javascript");
console.log(topics.join(", "));
What you should see · example output
terminal, javascript
3. Comments and scope
// starts a line comment. Use comments to explain a decision rather than describe every symbol. let and const are block-scoped: a name declared inside an if body is not available after that block. Avoid var while learning so the binding rules stay consistent.
if (true) {
const message = "Inside the block";
console.log(message);
}
console.log("Outside the block");
What you should see · example output
Inside the block Outside the block
YOUR TURN
A small check before you continue
Which declaration fits a fixed filename and which fits a running counter?
Show a suggested answer
Use const for a filename binding that will not be reassigned, and let for a counter that changes. This does not itself make a file or validate its path.
Sources and scope
Documentation and examples reviewed 2026-10-18. Provider screens, package versions and output wording can differ. Examples show expected outcomes; they are not a claim that OpenViST connected to your server or verified your setup.
