JS Variables
JavaScript variables are containers for storing data values.
Variables are named containers that store values you can reuse throughout your program. JavaScript gives you three keywords to declare them.
| Keyword | Reassignable | Scope | Use When |
|---|---|---|---|
const | ❌ No | Block | Value won’t change (recommended default) |
let | ✅ Yes | Block | Value will change |
var | ✅ Yes | Function | Old code — avoid in modern JS |
Try It — Variables in Action
Preview
Variable Naming Rules
- Must start with a letter,
$, or_ - Can contain letters, digits,
$,_ - Case sensitive —
name≠Name - Cannot be a reserved keyword (
let,if,return, etc.)
Tip: Good variable names describe what the value means:
userName,totalPrice,isLoggedIn. Avoid single letters likexor vague names likedata.