Character Data Type
Character Data Type wo data type hota hai jisme hum ek single character store karte hain jaise 'A', 'z', '1', '$', '@' etc. Real-world me jaha bhi letters, symbols, digits, input reading, names ke initials ya text ke characters use hote hain, waha Character data type ka role hota hai. Is guide me hum Character data type ka basic se lekar advanced concept tak sab kuch deep me samjhenge.
Character Data Type Kya Hota Hai?
Character Data Type ek single character ko store karta hai. Character hamesha single quotes (' ') me likha jata hai. Examples:
- 'A'
- 'z'
- '9'
- '#'
- ' '
Character data type internal memory me numeric codes (ASCII/Unicode) ke form me store hota hai.
Isse “Character” Kyun Kehte Hain?
Isse Character isliye bola jata hai kyunki ye ek text ka ek chhota hissa hota hai, jise hum character kehte hain. Computer internally characters ko ASCII ya Unicode code convert karke store karta hai. Character values include:
- Letters (A-Z, a-z)
- Digits (0-9)
- Symbols (@, #, $, %)
- Special characters (\n, space, tab)
Character data text, strings aur input handling ka base hota hai.
Character Ka Size Aur Range
Character data type aam taur par 1 byte (ASCII) ya 2 bytes (Unicode) memory use karta hai (language par depend karta hai).
Iska range hota hai: 0 – 255 (ASCII) ya 0 – 65,535 (Unicode)
Character Precision (Accuracy)
Character me precision ka matlab hota hai ek exact character ko sahi unicode/ASCII code ke saath represent karna. Isme floating point precision jaisa concept nahi hota.
'A' → ASCII 65
'a' → ASCII 97
'0' → ASCII 48
Character Ki Internal Working (Advanced)
Character memory me internally numeric code (ASCII ya Unicode) ke form me store hota hai. Example:
- 'A' → 65
- 'B' → 66
- 'a' → 97
- ' ' (space) → 32
CPU character ke numeric codes ke base par comparison aur operations perform karta hai.
Character vs String – Comparison
| Feature | Character | String |
|---|---|---|
| Meaning | Single character | Sequence of characters |
| Memory | Very low | More (depends on length) |
| Speed | Super fast | Slower than char |
| Use Case | Letters, symbols | Names, text, sentences |
Advantages of Character
- Memory usage bahut kam
- Fast processing
- Text aur strings ka base type
- Input handling me useful
Disadvantages of Character
- Sirf ek character store kar sakta hai
- Complex text seedhe store nahi kar sakta
- Comparison numeric codes par hota hai
JavaScript Example Programs
1. Basic Character Example
let letter = 'A'; console.log(letter);
2. Character Code (ASCII) Check
let ch = 'a'; console.log(ch.charCodeAt(0));
3. Character Comparison
let c1 = 'A'; let c2 = 'B'; console.log(c1 < c2);
4. Character from ASCII Value
console.log(String.fromCharCode(65));
5. Character Check (Letter or Not)
let c = '5'; console.log(isNaN(c));
Final Summary
Character Data Type ek single character store karta hai — letters, digits, symbols ya whitespace. Ye kam memory use karta hai aur text-processing ka base hota hai. Strings, text input, names, characters aur encoding systems sab Character data type par depend karte hain.
Comments
Post a Comment