← Back to JavaScript Course | Chapter 2: Functions & Objects | Lesson 3 of 10

JS डेटा टाइप्स

किसी junk drawer को labeled containers में छाँटने की कल्पना करें, एक में coins, दूसरे में paperclips, तीसरे में notes, हर container एक अलग तरह की चीज़ रखता है, और आप स्वाभाविक रूप से जानते हैं कि हर एक के अंदर क्या मिलेगा। JavaScript हर value को data types के एक छोटे से सेट में organize करता है, टेक्स्ट के लिए strings, गणित के लिए numbers, true/false के लिए booleans, और कुछ और specialized types, हर एक उसके साथ काम करते समय अलग व्यवहार करता है। यह पहचानना कि आप किस type से डील कर रहे हैं, चाहे cookiescursor.com पर कोई tutorial पढ़ रहे हों या अपना code debug कर रहे हों, JavaScript के रोज़मर्रा के व्यवहार का एक बड़ा हिस्सा समझाता है।
Syntax
javascript
let text = "string";
let number = 10;
let flag = true;
let list = [item1, item2];
let object = { key: value };

String, Number और Boolean

string उद्धरण चिह्नों में लिपटे text को दर्शाता है, number पूर्ण और दशमलव दोनों संख्याओं को एक ही type से दर्शाता है, और boolean केवल true या false दर्शाता है, रोज़मर्रा की JavaScript में सबसे आम तौर पर इस्तेमाल होने वाले तीन data types।

Note: कई भाषाओं के विपरीत, JavaScript पूर्ण और दशमलव दोनों के लिए एक ही number type इस्तेमाल करती है, int बनाम float जैसा कोई अलग भेद नहीं है।
Warning: Numbers written without quotes and text written with quotes look similar but behave very differently in arithmetic and comparisons.

उदाहरण: String, Number, and Boolean

javascript
// Declare the variable `name`, set to "Alice"
// Declare the variable `name`, set to "Alice"
let name = "Alice";
// Declare the variable `age`, set to `30`
// Declare the variable `age`, set to `30`
let age = 30;
// Declare the variable `isActive`, set to `true`
// Declare the variable `isActive`, set to `true`
let isActive = true;
// Print `typeof name, typeof age, typeof isActive` to the console
// Print `typeof name, typeof age, typeof isActive` to the console
console.log(typeof name, typeof age, typeof isActive);

undefined और null

undefined का मतलब है कि variable घोषित हुआ है पर उसे कभी value नहीं दिया गया, जबकि null एक इरादतन value है जो developers 'कुछ नहीं' या 'जानबूझकर खाली' दर्शाने के लिए देते हैं, दोनों असली value की अनुपस्थिति का अर्थ रखने के बावजूद अलग अवधारणाओं को दर्शाते हैं।

Note: एक मददगार मानसिक मॉडल, undefined का आमतौर पर मतलब है कि यह भाषा ने अपने-आप किया, null का आमतौर पर मतलब है कि यह किसी developer ने जान-बूझकर सेट किया।
Warning: typeof null returns object, a famous historical bug in JavaScript that's been kept for compatibility rather than fixed.

उदाहरण: undefined and null

javascript
let notSet;
let empty = null;
console.log(notSet); // undefined
console.log(empty);  // null

bigint और symbol

bigint उन पूर्ण संख्याओं को दर्शाता है जो सामान्य number type सुरक्षित रूप से नहीं संभाल सकता, जो n suffix के साथ लिखी जाती हैं, जबकि symbol एक गारंटीशुदा अद्वितीय value बनाता है, जो अक्सर विशेष, टकराव-मुक्त property key के रूप में इस्तेमाल होता है।

Note: bigint केवल अत्यंत बड़े integers के लिए ज़रूरी है, बहुत बड़े IDs या सटीक बड़ी-संख्या गणित वाली गणनाएँ इसके आम उपयोग हैं।
Warning: You cannot mix a regular number and a bigint directly with arithmetic operators, doing so throws a TypeError.

उदाहरण: bigint and symbol

javascript
// Declare the variable `big`, set to `12345678901234567890n`
// Declare the variable `big`, set to `12345678901234567890n`
let big = 12345678901234567890n;
// Declare the variable `id`, set to `Symbol("id")`
// Declare the variable `id`, set to `Symbol("id")`
let id = Symbol("id");
// Print `typeof big, typeof id` to the console
// Print `typeof big, typeof id` to the console
console.log(typeof big, typeof id);

object Type

object इकलौता non-primitive type है, जो संबंधित data और functionality को एक साथ समूहित करने के लिए इस्तेमाल होता है, और इसमें केवल साधारण objects ही नहीं बल्कि arrays, functions और dates भी आते हैं, जो सभी typeof के साथ object या function बताते हैं।

Note: जब आपको कई संबंधित जानकारियाँ एक साथ store करनी हों, जैसे किसी user का नाम और email, तो object आमतौर पर सही type है।
Warning: Arrays report typeof as object, not array, use Array.isArray() specifically when you need to confirm something is an array.

उदाहरण: The object Type

javascript
// Declare the variable `user`, set to `{ name: "Sam" }`
// Declare the variable `user`, set to `{ name: "Sam" }`
let user = { name: "Sam" };
// Declare the variable `list`, set to `[1, 2, 3]`
// Declare the variable `list`, set to `[1, 2, 3]`
let list = [1, 2, 3];
// Print `typeof user, typeof list` to the console
// Print `typeof user, typeof list` to the console
console.log(typeof user, typeof list);

Dynamic Typing

JavaScript dynamically typed है, यानी declaration के समय variable का type तय नहीं होता, वह इस बात से तय होता है कि उसके अंदर अभी कौन सा value बैठा है, और वह value, अपने type के साथ, बदल सकता है अगर variable को दोबारा assign किया जाए।

Note: Dynamic typing लचीलापन देती है, लेकिन एकसमान code लिखना, यानी variable के इच्छित type को उसके जीवनकाल में स्थिर रखना, उलझन भरे bugs घटाता है।
Warning: Accidentally reassigning a variable to an unexpected type, like changing a number to a string mid-script, can cause subtle downstream errors.

उदाहरण: Dynamic Typing

javascript
let value = 5;
console.log(typeof value); // "number"
value = "now a string";
console.log(typeof value); // "string"
Live Example
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह मान लेना कि null और undefined एक ही चीज़ हैं, वे related हैं लेकिन अलग-अलग intended meanings वाली distinct values हैं।
  2. यह भूल जाना कि JavaScript dynamically typed है, यानी किसी variable का type बदल सकता है अगर आप उसे किसी अलग तरह की value reassign करें।
  3. null check करने के लिए typeof इस्तेमाल करना, क्योंकि typeof null एक long-standing language quirk की वजह से गलती से object return करता है।
चैप्टर सारांश
  • JavaScript के primitive types हैं string, number, bigint, boolean, undefined, null, और symbol, साथ ही non-primitive object type।
  • typeof runtime पर किसी value का type check करने का standard तरीका है।
  • JavaScript dynamically typed है, किसी variable का type उसकी current value से तय होता है और समय के साथ बदल सकता है।
ब्राउज़र सपोर्ट

सभी core JavaScript data types language standard का हिस्सा हैं और हर modern browser में समान रूप से व्यवहार करते हैं; BigInt सभी current browser versions में supported है।

🔒

Chapter Quiz — Complete all 10 topics to unlock

0/10 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.