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

JS Data Types

Imagine sorting a junk drawer into labeled containers, coins in one, paperclips in another, notes in a third, each container holds a different kind of thing, and you naturally know what to expect inside each one. JavaScript organizes every value into a small set of data types, strings for text, numbers for math, booleans for true/false, and a few more specialized types, each behaving differently when you work with it. Recognizing which type you're dealing with, whether reading a tutorial on cookiescursor.com or debugging your own code, explains a huge portion of JavaScript's everyday behavior.
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. #}
🔒

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.