JavaScript is dynamically typed, meaning variables hold values of any type without fixed type annotations. The language has seven primitive types and one reference category (object), which includes arrays, functions, dates, and maps.
Primitive values are immutable and copied by value. Reference values (objects and arrays) are mutable and copied by memory reference.
"Ada".NaN and Infinity.n, such as 9007199254740993n.true or false.Date, Map, and Set.Copying a primitive creates an independent copy, while copying an object variable points both names at the same object in memory.
// Primitives copy by value
let a = 10;
let b = a;
b = 20;
console.log("Primitives:", a, b); // 10, 20
// Objects copy by reference
const original = { theme: "light" };
const alias = original;
alias.theme = "dark";
console.log("Original mutated:", original.theme); // "dark"
// Shallow copy with spread prevents shared mutation
const safeCopy = { ...original, theme: "sepia" };
console.log("Safe copy vs original:", safeCopy.theme, original.theme);
typeof null: Due to a legacy 1995 bug, typeof null returns "object". Check value === null explicitly.typeof to detect arrays: typeof [1, 2] returns "object". Always use Array.isArray(value) instead.null and undefined in JavaScript?undefined means a variable or property has not been assigned a value yet. null is a value you explicitly assign to show "no object" or "empty on purpose."
Methods like "abc".toUpperCase() return a brand-new string "ABC" without altering the original string in memory.
Modern browsers and Node.js support structuredClone(obj), which clones nested objects, arrays, and Date values cleanly.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.