Variables
Think about your mobile phone. It keeps your contacts, your photos, your battery percentage, and whether Wi-Fi is on or off. All of this is data, and each piece is a different kind of data.
JavaScript also works with data all the time. To use data, we first need a place to keep it, and we need to know what kind of data it is. That is what this lesson is about.
Variables: A Quick Introduction
A variable is like a container with a sticker on it. The sticker is the name, and inside the container is the value.
studentNameandmarksare the names."Anjali"and92are the values.
JavaScript gives us three keywords to create variables:
| Keyword | Can the value change? | When to use |
|---|---|---|
const | ❌ No | Use this by default |
let | ✅ Yes | When the value will change |
var | ✅ Yes | Old style, avoid it |
Key Takeaways
- A variable stores a value. Use
constby default andletwhen the value will change.