🎯 By the end of this lesson you can…
- Create variables with let and const
- Update a variable’s value
- Choose clear, legal names
Boxes with labels
⚡ JavaScript
variables.js
👆 Tap a line to explain it
1let coins = 10;2console.log(coins);3coins = 15;4console.log(coins);5coins = coins + 5;6console.log(coins);
const: the sealed box
⚡ JavaScript
const.js
👆 Tap a line to explain it
1const birthday = "12 March";2console.log(birthday);3birthday = "13 March";
Naming rules
| ✅ Good | ❌ Not allowed / not great | Why |
|---|---|---|
totalScore | total score | no spaces |
player2 | 2player | can’t start with a digit |
isHappy | x | say what it means |
firstName | let | reserved words are taken |
JavaScript is case-sensitive: score and Score are two different boxes.
🔮 What will this display?
What does this print?
1let a = 5;2let b = a;3a = 10;4console.log(b);
🐞 Find the error
Why does this code crash?
1const lives = 3;2lives = lives - 1;
🛠️ Swap the drinks
You have let cupA = "tea"; and let cupB = "coffee";. Swap them so cupA holds coffee and cupB holds tea, then print cupA cupB with console.log(cupA, cupB).
📌 Key takeaways
const= sealed box (can’t be reassigned).let= box you can change.- Use
constby default; useletwhen the value must change. - Names are case-sensitive and use camelCase:
totalScore.
Finished reading & practising?
Saved in this browser. Create a free account to keep it forever.