Tá 7 primitive types i JavaScript, agus is object a bhíonn i ngach rud eile (arrays, functions, objects).
Na primitives: string, number, boolean, , , , .
Tá 7 primitive types i JavaScript, agus is object a bhíonn i ngach rud eile (arrays, functions, objects).
Na 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. Tá primitive types immutable agus cóipeáilte de réir value; cóipeáilte de réir reference a bhíonn 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" is earráid bhuan teanga a chaithfidh tú a chuimhneachán — chun null a sheiceáil, déan comparáid dhíreach (x === null).
A thuiscint ar value-vs-reference míníonn sé cén fáth go mbíonn gníomhú ar object roinnte ag imirt ar "an dá" athróg, cén fáth a bhíonn {} === {} ina false, agus cén fáth a bhíonn tú ag cóipeáil objects (spread) sula n-athraíonn tú iad i UIs atá tiomantaithe ag stát cosúil le React.