JavaScript Data Types (Basic समझ)
Data Type मतलब:
आप variable में किस type का data store कर रहे हो
1. Number
Numbers = integer + decimal दोनों
let age = 25;
let price = 99.99;
✔ Examples:
- 10
- 3.14
- -5
Use: जब आपको calculation करनी हो
2. String
Text / words को String कहते हैं
let name = "Robin";
let city = 'Lucknow';
✔ Examples:
- "Hello"
- 'JavaScript'
- "123" (⚠️ ये number नहीं, string है)
Use: जब text store करना हो
3. Boolean
सिर्फ 2 values होती हैं:
- true
- false
let isLoggedIn = true;
let isAdmin = false;
Use: decision लेने में
if (isLoggedIn) {
console.log("Welcome");
}
4. Null
मतलब: जानबूझकर empty value
let data = null;
समझो:
"मेरे पास value है, लेकिन अभी खाली है"
✔ Example:
- user data अभी load नहीं हुआ
5. Undefined
मतलब: value assign ही नहीं हुई
let x;
console.log(x); // undefined
समझो:
"variable बनाया, लेकिन कुछ डाला ही नहीं"
6. Object
सबसे important और powerful data type
Object = multiple values एक साथ
let user = {
name: "Robin",
age: 25,
isAdmin: true
};
Access:
console.log(user.name); // Robin
Use: real-world data (user, product, etc.)
Quick Comparison (Easy Table)
| Data Type | Example | Meaning |
|---|---|---|
| Number | 10, 3.14 | Numbers |
| String | "Hello" | Text |
| Boolean | true / false | Yes/No |
| Null | null | Empty (intentional) |
| Undefined | undefined | Value नहीं दी |
| Object | {name: "Robin"} | Multiple data together |
Real Life Example (सब एक साथ)
let user = {
name: "Robin", // string
age: 25, // number
isLoggedIn: true, // boolean
lastLogin: null // null
};
let x; // undefined
Pro Tips (Beginner → Pro)
"123" ≠ 123 (string vs number)null और undefined अलग हैं ⚠️- Objects सबसे important हैं (React/Vue में बहुत use होते हैं)
- Always check type:
console.log(typeof "Hello"); // string
console.log(typeof 10); // number


0 Comments