What are Variables?
A variable is like a labeled box that stores a value. You give the box a name, and you can put something inside it.
Creating Variables
Use let and = to store a value in a variable:
If a value never changes, use const instead:
Types of Values
Strings — text inside quotes:
Numbers — whole numbers and decimals:
Booleans — true or false (always lowercase in JavaScript!):
Naming Variables
JavaScript names are usually written in camelCase: the first word is lowercase, and every next word starts with a capital letter, like myName or highScore. Names can't contain spaces or start with a number.
Using Variables
You can use variables in console.log():
Output:
Alex
You can log variables with text:
Output:
Hello, Alex
Changing Variables
You can change what's inside a variable made with let:
Output:
0 100
The old value is replaced by the new one. Notice you only write let the first time — after that, just use the name.