JS-002

Beginner3 min~3 min read#let#const#variables
let vs const
Can the value change?
Goal
Understand when to use let and when to use const.
Explanation
- JavaScript offers two modern ways to create variables.
- const means the variable must always refer to the same value.
- let means you can change the value later.
- If you do not plan to change anything — use const.
- If the value will change while the program runs — use let.
Analogy
const is a locked box. let is a regular box you can open and change what is inside.
Code
let score = 10;
score = 20;
const age = 30;
// age = 31 ❌Result: TypeError: Assignment to constant variable.
Common mistake
Many people think const makes data completely immutable. In reality, it only prevents reassigning the variable itself.
Remember
- ✦ let can be changed.
- ✦ const cannot be reassigned.
- ✦ Use const by default.
Quick Quiz
Which variable should you use by default?