JavaScript には 7つのプリミティブ型 があり、それ以外のすべて(配列、関数、オブジェクト)は object です。
プリミティブは次のとおりです。string、number、boolean、null、undefined、、。
bigintsymboltypeof "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. プリミティブはイミュータブルで値によってコピーされ、オブジェクトは参照によってコピーされます。
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)。
値 vs 参照を理解することで、共有オブジェクトを変更すると「両方の」変数に影響する理由、{} === {} が false になる理由、そして React のような状態駆動の UI で状態を変更する前にオブジェクトを(spread で)コピーする理由が説明できます。