Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

JavaScript has seven primitive types: undefined, null, boolean, number, bigint, string, and symbol. Values that are not primitive are objects, including arrays and functions. The distinction matters because primitives are immutable, while objects can be changed and shared through multiple references.

What are primitive and non-primitive values in JavaScript?

A primitive is a value that is not an object. An object is a value that can have properties and refer to other values. “Non-primitive” is commonly used as a contrast term for objects, though JavaScript documentation often simply calls them objects. A variable does not have to keep one category: JavaScript values have types, and a variable can later be assigned a value of a different type.

MDN Web Docs describes the key mutability distinction this way: “In JavaScript, objects are the only mutable values.” Primitive values cannot be changed in place; object properties or state can be changed. This describes observable language behavior, not a prescribed physical memory layout.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The seven primitive types

  • undefined — a value commonly seen for a declared variable that has not been assigned a value.
  • null — a primitive value used to represent an intentional absence of a value.
  • boolean — true or false.
  • number — numbers such as 42 and 3.14.
  • bigint — integers of arbitrary size, written with an n suffix, such as 1n.
  • string — text such as "hello".
  • symbol — a unique primitive value, commonly created with Symbol().

Examples of objects

Ordinary object literals, arrays, dates, and functions are objects. An array is an object even though it is designed to hold a collection of values. A function is a callable object; JavaScript gives it a special typeof result.

const person = { name: "Ada" }; // ordinary object
const scores = [10, 20];        // array object
const today = new Date();       // date object
const greet = () => "Hello";    // function object

How do primitive and object values behave differently?

Assignment makes the distinction visible. When one variable is assigned a primitive value, changing the first variable later does not change the value held by the second. When one variable is assigned an object held by another, both variables can refer to that same object. Mutating it through either binding is observable through the other.

let first = 10;
let second = first;
first = 20;
console.log(second); // 10

const original = { score: 10 };
const alias = original;
alias.score = 20;
console.log(original.score); // 20

The object example shows shared access to one object, not that reassigning one variable reassigns the other. For example, assigning a different object to alias would not change what original refers to. Also, const prevents rebinding the original variable; it does not make the object it refers to immutable.

Strings illustrate immutability: an operation that appears to alter text produces a string value rather than changing an existing string in place. Objects, by contrast, can have their properties changed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How can you identify primitive values, arrays, and null?

typeof is useful for many primitive types, but it is not a complete taxonomy of JavaScript values. In particular, it returns "object" for null and arrays. Use a direct comparison for null and Array.isArray() for arrays.

if (value === null) {
  // null primitive
} else if (Array.isArray(value)) {
  // array object
} else {
  console.log(typeof value);
}
Value typeof result What to know
undefined "undefined" Primitive
null "object" Primitive; the result is a historical JavaScript quirk
Boolean "boolean" Primitive
Number "number" Primitive
BigInt "bigint" Primitive
String "string" Primitive
Symbol "symbol" Primitive
Function "function" Callable object with a special result
Array or other object "object" Use a more specific check when needed; Array.isArray() identifies arrays

The typeof result is not a constructor name or a complete description of an object’s kind. For example:

console.log(typeof null); // "object"
console.log(typeof []);   // "object"
console.log(typeof (() => {})); // "function"
console.log(Array.isArray([])); // true

Why can primitive strings and numbers have methods?

JavaScript can temporarily wrap most primitive values when you access a property or method on them. That convenience does not turn a primitive literal into an object. For example, a string can use string methods while remaining a primitive value.

An explicit wrapper is different: new String("hello") creates a String object, while "hello" is a primitive string. This difference is visible with instanceof:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
console.log("hello" instanceof String); // false
console.log(new String("hello") instanceof String); // true

Wrapper objects are not a general-purpose way to test primitive values. instanceof checks prototype relationships for objects; it does not recognize primitive strings as String instances.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When should you use each kind?

Use primitives for standalone values such as text, flags, numeric quantities, or an explicit absence represented by null. Use objects when your program needs a value with properties or related state; arrays represent ordered collections, and functions represent callable behavior. The distinction is about the value’s category and behavior, not a rule that one category is always preferable.

When checking a value, start with typeof for the primitive categories it identifies, explicitly check null, and use Array.isArray() for arrays. If you need to distinguish other object kinds, use a check appropriate to that particular kind rather than treating typeof or instanceof as a universal detector.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.