LESSON 04 / 07

Variables: let and const

Variables are labelled boxes that remember values. Learn let, const, good names, and how to change what’s inside.

🎓Beginnerlevel
⏱️30 minto finish
✏️3activities

📂 First Steps in JavaScript🏷️ Variables

🎯 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 greatWhy
totalScoretotal scoreno spaces
player22playercan’t start with a digit
isHappyxsay what it means
firstNameletreserved 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 const by default; use let when 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.