Beginner Codes/JavaScript/Variables (let, const)
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 let when the value will change
  • Use const when 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 prefers let and const.

Your Turn!

Create a constant called language with the value "JavaScript" and print it.

Help

Variables (let, const)Exercise 2/1015 XP
❴❵ script.js
javascript.code
javascript
Loading...
Terminal
Terminal — javascript
Beginner Codes Terminal v1.0.0
─────────────────────────────────────
Ready. Click "Run Code" to execute...
Ready
Piston APIJAVASCRIPT0 lines