Variables
Variables store values so you can use and reuse them later. JavaScript has three ways to declare one.
let and const
let declares a variable that can be reassigned later. const declares one that can't be reassigned once set — use it as your default unless you know the value needs to change.
Naming rules
- Names can contain letters, numbers,
$, and_— but can't start with a number. - Names are case-sensitive:
scoreandScoreare different variables. - By convention, JavaScript variables use camelCase — like
firstName, notfirst_name.
Note:
var is an older way to declare variables, from before let and const existed. You'll still see it in older code, but modern JavaScript almost always uses let and const instead.