string | number | boolean |undefined|null| symbol | bigint
Example
const name ="Mira";// stringconst age =28;// numberconst active =true;// booleanconst missing =undefined;// undefinedconst empty =null;// nullconst id =Symbol("id");// symbolconst big =900719925474099267n;// bigint
Note Primitives are immutable and compared by value. There are 7 primitive types in total.
Note typeof null === "object" is a historic bug that will never be fixed. Use value === null for null checks. Arrays report as "object" -- use Array.isArray() instead.
Note Only triggers on null/undefined, unlike || which triggers on all falsy values (0, "", false, NaN). Use ?? when 0 or empty string are valid values.
const user ={ profile:{ avatar:"pic.png"}};console.log(user?.profile?.avatar);// "pic.png"console.log(user?.settings?.theme);// undefinedconsole.log(user?.getName?.());// undefined (no error)
Note Short-circuits to undefined when a link in the chain is null/undefined. Combine with ?? for defaults: user?.name ?? "Guest"