Variables
Variables store values. In JavaScript we use let or const. Use const when the value won't change, let when it might.

Appy Says…
JavaScript has three ways to create variables: var (old, avoid it), let (use when the value changes), and const (use when it stays fixed). Knowing which to use makes your code cleaner and avoids subtle bugs.
Variables in JavaScript
A variable stores a value under a name. JavaScript gives you three keywords for creating them — each with different rules about whether the value can change:
- •
const name = "Alex";— the value never changes (constant) - •
let score = 0;— the value can change (use this for most things) - •
var— old style, has quirky rules. Avoid in modern code. - •Use camelCase for names:
playerScore,highScore,isLoggedIn
const vs let — like a fixed vs adjustable setting
const is like your game's resolution setting — you set it once at the start and it never changes. let is like your volume slider — it changes every time you adjust it. Pick the right one based on whether the value needs to change.
Real-World Examples
- •
const APP_NAME = "TikTok";— the name never changes - •
let viewCount = 0; viewCount++;— the view count grows with every view - •
const userId = "abc123";— once you log in, your ID is fixed - •
let currentTrack = playlist[0]; currentTrack = playlist[1];— the current song changes
Key Facts
- •JavaScript uses
+to join strings:"Hello " + name - •Template literals (backticks) are cleaner:
`Hello ${name}!` - •
typeof xtells you the type of a variable - •Reassigning a
constthrows a TypeError — use it to protect important values - •
letandconstare block-scoped — they only exist inside the{}where they're defined
Remember
Default to const. Only switch to let when you know the value will change. Never use var in new code. This is the rule used in every modern JavaScript project.
What You Learned
- •
constfor values that never change;letfor values that do - •camelCase naming:
playerScore,isLoggedIn - •Template literals:
`Hello ${name}!`— cleaner than string concatenation - •
typeof xchecks the type at runtime - •Avoid
varin modern JavaScript
Key Facts
- →JavaScript uses
+to join strings:"Hello " + name - →Template literals (backticks) are cleaner:
`Hello ${name}!` - →
typeof xtells you the type of a variable - →Reassigning a
constthrows a TypeError — use it to protect important values - →
letandconstare block-scoped — they only exist inside the{}where they're defined
Real-World Examples
Remember
Default to const. Only switch to let when you know the value will change. Never use var in new code. This is the rule used in every modern JavaScript project.
Quick Quiz
Which keyword is for values that don't change?