Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk3 min

JavaScript Primitive vs. Object Types: What Changes and How to Tell

JavaScript has seven primitive types and a broad category of object values. Learn how immutability, assignment, typeof, arrays, functions, and string methods reveal the difference.

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.

JavaScript has seven primitive types—undefined, null, boolean, number, bigint, string, and symbol—and one broad category of object values. The key difference is that primitives are immutable values, while objects can hold mutable properties and be shared through multiple bindings. “Non-primitive” is a common informal label for objects, but null is still a primitive despite what typeof reports.

Primitive and object types at a glance

Question Primitive Object (often called non-primitive)
What is it? A value that is not an object An object value, including arrays and functions
Can it be changed in place? No. Primitive values are immutable. Object properties or state can ordinarily be changed.
What happens when assigned? The other binding receives that primitive value. Bindings can refer to the same object, so a mutation through one can be seen through the other.
Common examples "hi", 42, true, null, undefined, 1n, Symbol() {}, [], new Date(), and functions

MDN summarizes the mutability distinction by noting that objects are JavaScript’s only mutable values. The categories describe values, not fixed types assigned permanently to variables: a binding can later be assigned a value of another type.

As an Amazon Associate I earn from qualifying purchases.

Which values are primitives?

The seven primitive types are undefined, null, boolean, number, bigint, string, and symbol. A primitive is not an object. null belongs on this list even though the historical behavior of typeof null is unusual.

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

Strings and numbers cannot be altered in place. For example, an operation that produces a different string gives you a new primitive value; it does not edit the original string. This is distinct from an object whose properties can be modified.

Arrays, functions, and ordinary objects are objects

Array literals such as [], object literals such as { score: 10 }, dates, and functions are object values. Arrays are objects even though they are designed to represent ordered collections. Functions are callable objects; typeof reports the special string "function" for them.

It is therefore inaccurate to define “non-primitive” as “contains several values.” The decisive distinction is whether the value is an object. An array is an object by category, regardless of how many items it contains.

How assignment and mutation differ

When one primitive value is assigned to another binding, changing the first binding later does not change the second. With objects, two bindings can refer to the same object; changing one of its properties through either binding is visible through the other. Reassigning a binding is still separate from mutating the shared object.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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

const prevents rebinding original or alias; it does not make the object they refer to immutable. These examples describe observable JavaScript behavior without assuming a particular physical memory layout.

How to check a value’s type

typeof is useful for many primitive categories, but it is not a complete taxonomy of object kinds. In particular, it returns "object" for both null and arrays, and "function" for callable functions.

Value category typeof result
undefined "undefined"
null "object" (historical quirk)
Boolean "boolean"
Number "number"
BigInt "bigint"
String "string"
Symbol "symbol"
Function "function"
Other objects, including arrays "object"

Handle the common exceptions explicitly:

if (value === null) {
  // null primitive
} else if (Array.isArray(value)) {
  // array object
} else {
  console.log(typeof value);
}

Use value === null to identify null and Array.isArray(value) to identify arrays. For other object categories, use a check suited to the particular type. instanceof is not a universal primitive-versus-object detector.

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

Why can a primitive string have methods?

JavaScript temporarily wraps most primitive values when property access or a method call needs it. That convenience does not turn a primitive literal into an object. For example, "hello" is a primitive string, while new String("hello") creates a String wrapper object. The distinction is observable 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

For ordinary string values, prefer the primitive form rather than explicitly creating a wrapper object.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.