🌐 JavaScript Variables
🟢 What is a Variable?
A variable is like a box where we can store information (data) and use it later in our program.
👉 Example in real life:
Think about a water bottle. You can fill it with water, drink it, and refill it again. Similarly, a variable can hold a value, and we can change or update that value later.
🟢 How to Declare a Variable in JavaScript?
We use keywords like var, let, and const to declare (create) variables.
1. var
Older way of creating variables.
2. let
Modern and commonly used way to declare variables.
3. const
Used when the value should not change.
🟢 Variable Naming Rules
When naming a variable, remember these rules:
✔ Must start with a letter, _ (underscore), or $ (dollar sign).
✔ Cannot start with a number.
✔ No spaces are allowed.
✔ JavaScript is case-sensitive (Name and name are different).
✅ Examples:
❌ Invalid examples:
🟢 Updating Variables
🟢 Why are Variables Important?
-
They help store information.
-
They make code reusable and flexible.
-
They make programs easy to understand.
💡 Quick Summary:
-
Use
letfor normal variables. -
Use
constfor values that should not change. -
Use
varonly if working with older code.

Comments
Post a Comment