📖
What is a Variable?
Understand what a variable is with simple analogies
📦
Variable = box
Imagine you have boxes on a shelf. Each box has a label — like 'Name' or 'Age'. Inside the box is some information. A variable in programming is the same thing: it has a name and stores some value.
javascript
💬
Here we created three variables: name, age, and city. Each stores its own value.
In JavaScript there are three ways to create a variable:
let— a regular variable that can be changedconst— an unchangeable variable (constant)var— old syntax (better not to use)
🔒
let vs const
let is a regular box you can open and change the contents. const is a sealed box you cannot open and change. For example, pi (3.14) never changes — so it's const.
javascript
💬
let can be changed, const cannot.