Back

Variables

Variables store information your program can use later. Think of them like labeled boxes: you give the box a name and put something inside. There are three ways to create variables: - `const`: the value never changes (use this by default) - `let`: the value can change - `var`: old way, avoid it When to use what: Use `const` for everything by default. Switch to `let` only when you know the value will change, like a counter or a loop variable.

const name = "Daniel"   // never changes
let score = 0           // can change
score = 10              // allowed with let

const age = 20
// age = 21  // ERROR: const cannot be reassigned

Roadmap