JavaScript nduweni 7 tipe primitif, lan kabeh liyane (array, fungsi, object) iku object.
Primitif-e: string, number, boolean, null, , , .
JavaScript nduweni 7 tipe primitif, lan kabeh liyane (array, fungsi, object) iku object.
Primitif-e: string, number, boolean, null, , , .
undefinedbigintsymboltypeof "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. Primitif iku immutable lan dikopèkake miturut nilai; object dikopèkake miturut referensi.
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" iku bug basa sing wis lawas kudu dieling-eling — kanggo pariksa null, bandingne langsung (x === null).
Pahami nilai-versus-referensi njlentrehake kenapa mutasi object bersama mengaruhi "loro-lorone" variabel, kenapa {} === {} iku false, lan kenapa sampeyan kudu nglumpukake object (spread) sadurunge ngowahi uga ing UI sing gumantung-gantung state kaya React.