JavaScript-ல் 7 primitive types உள்ளன, மேலும் மற்ற எல்லாவும் (arrays, functions, objects) object ஆக இருக்கிறது.
Primitives: string, number, boolean, , , , .
JavaScript-ல் 7 primitive types உள்ளன, மேலும் மற்ற எல்லாவும் (arrays, functions, objects) object ஆக இருக்கிறது.
Primitives: 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. Primitives மாற்ற முடியாது மற்றும் மதிப்பால் நகல் செய்யப்படும்; objects reference மூலம் நகல் செய்யப்படும்.
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" நீண்ட நாளிய மொழி bug ஆக இருக்கிறது, நீ நினைவில் கொள்ள வேண்டும் — null ஐ சரிபார்க்க, நேரடியாக compare செய் (x === null).
Value-vs-reference ஐ புரிந்துகொள்வது பகிரப்பட்ட object ஐ mutate செய்வது இரண்டு variables ஐ பாதிக்கிறது என்பதை, {} === {} ஏன் false என்பதை, மற்றும் React போன்ற state-driven UI-களில் objects ஐ நகল் செய்வதற்கு (spread) முன் ஏன் நீ மாற்றுகிறாய் என்பதை விளக்குகிறது.