10%
Instructions
Variables (let, const) 📦
Variables store data that your program can use and manipulate.
let vs const
JavaScript has two main ways to declare variables:
let score = 0; // Can be changed later
const name = "Beginner Codes"; // Cannot be changed
- Use
letwhen the value will change - Use
constwhen the value stays the same
Examples
let lives = 3;
console.log(lives); // 3
lives = 2; // ✅ This works with let
console.log(lives); // 2
const PI = 3.14159;
// PI = 3; ❌ This would cause an error!
💡 Did You Know? There's also
var, but it's the old way of declaring variables. Modern JavaScript prefersletandconst.
Your Turn!
Create a constant called language with the value "JavaScript" and print it.
Help
Variables (let, const)Exercise 2/10 • 15 XP
❴❵ script.js
Terminal