A variable is a container for a value. Think of it like a labeled box.
What is a Variable?
Imagine you're moving house. You have a lot of stuff. You need BOXES to store things. In programming, a VARIABLE is just a labeled box where we store data.
Creating the Box (Declaration)
To use a box, you first have to create it. We use the keyword 'let' followed by a name. 'let score'. Now we have a box named 'score', but it's empty (undefined).
Filling the Box (Assignment)
Now let's put something inside! We use the equals sign '='. 'score = 0'. This puts the number 0 into the box. We can change it later: 'score = 10'.
The Unchangeable Box (const)
Sometimes you want a box that NEVER changes. Like assignment constants. Use 'const' instead of 'let'. 'const PI = 3.14'. If you try to change it later, the program will crash!
What about "var"?
You might see 'var' in old code. It's the grandfather of 'let'. But 'var' doesn't respect boundaries (scopes) like 'let' does. It leaks out of boxes. We use 'let' and 'const' now.
What Fits Inside? (Data Types)
Variables can hold different types of things. Strings (text) like "Mario", Numbers like 100, or Booleans (true/false switches). JavaScript figures out the type automatically.
Level Up!
You've mastered the art of storing data. Now let's learn how to create your own tools with Functions.