JavaScript मध्ये 7 प्राथमिक प्रकार आहेत, आणि बाकी सर्वकाही (arrays, functions, objects) object आहे.
प्राथमिक: string, number, boolean, , , , .
JavaScript मध्ये 7 प्राथमिक प्रकार आहेत, आणि बाकी सर्वकाही (arrays, functions, objects) object आहे.
प्राथमिक: string, number, boolean, , , , .
nullundefinedbigintsymboltypeof "hi"; // "string"
typeof 42; // "number" (both ints and floats)
typeof true; // "boolean"
typeof undefined; // "undefined"
typeof 10n; // "bigint"
typeof Symbol(); // "symbol"
typeof null; // "object" ← famous historical bug!
typeof {}; // "object"
typeof []; // "object" (arrays are objects)
typeof function(){};// "function"
1. प्राथमिक immutable आहेत आणि मूल्यानुसार कॉपी केले जातात; objects संदर्भानुसार कॉपी केले जातात.
let a = 5; let b = a; b++; // a is still 5 (independent copies)
let x = {n:1}; let y = x; y.n = 2; // x.n is now 2 (same object!)
2. typeof null === "object" हा दीर्घकाळ चालू असलेला भाषा बग आहे ज्याची तुम्हाला माहिती असणे आवश्यक आहे — null तपासण्यासाठी, थेट तुलना करा (x === null).
मूल्य-विरुद्ध-संदर्भ समजून घेणे स्पष्ट करते की सामायिक object ला mutate केल्याने दोन्ही व्हेरिएबल्सवर का परिणाम होतो, {} === {} का false आहे, आणि React सारख्या state-driven UI मध्ये त्यांना बदलण्यापूर्वी तुम्ही objects (spread) का कॉपी करता.