Best Division

Spread Your Knowledge

  • All topics
  • About us
  • Contact us
  • Privacy policy
  • Terms of service
  • Copyright
  • Facebook
  • Twitter
  • Instagram
  • Youtube
  • LinkedIn
  • Pinterest
  • Github
  • Tumblr

© 2026 Best Division

Which Data Types Are Non-Primitive in JavaScript?

JavaScript
Jayant Kumar
Jayant Kumar@jayantkumar314
PublishedOct 1, 2024
UpdatedNov 16, 2026
5 min read

In JavaScript, the only non-primitive data type is Object. Arrays, functions, dates, regular expressions, maps, sets and class instances are all kinds of objects. Everything else (Number, String, Boolean, Undefined, Null, BigInt and Symbol) is primitive.

The question usually appears in multiple-choice form. If the options include Array or Function, they count as non-primitive because they are objects.

Table of Contents

  • Primitive versus non-primitive values
  • Common built-in object types
  • How copying and comparison differ
  • The stack and heap explanation, corrected
  • Freezing objects
  • Detecting object types in practice
  • Frequently Asked Questions
    • Is an array primitive in JavaScript?
    • Is a function a primitive?
    • Is null primitive even though typeof says object?
    • Is a string an object?
  • Summary

Primitive versus non-primitive values

A primitive is an immutable value with no properties or methods of its own. A non-primitive value is an object: a collection of properties that can change after creation.

AspectPrimitiveNon-primitive (object)
TypesNumber, String, Boolean, Undefined, Null, BigInt, SymbolObject and its built-ins
MutableNo, the value cannot changeYes, properties can change
Compared byValueReference (identity)
Copied byValueReference to the same object

Common built-in object types

All of these are non-primitive:

javascript
javascript
Loading syntax highlighting...

typeof returns "function" for callable objects, but a function is still an object: it has properties and inherits from Object.prototype. Use Array.isArray() to tell an array from a plain object.

Primitive values can look like objects because the engine wraps them temporarily when you call a method, as in "abc".toUpperCase(). The wrapper is discarded afterwards, and the string itself stays a primitive.

How copying and comparison differ

Assigning a primitive copies the value. Assigning an object copies the reference, so both variables point to one object:

javascript
javascript
Loading syntax highlighting...

To make an independent copy, use a shallow copy such as { ...original } or [...list], or structuredClone(value) for a deep copy of plain data. structuredClone is available in current browsers and Node.js, and it throws on functions.

The stack and heap explanation, corrected

Many tutorials say primitives live on the stack and objects on the heap. That is a simplification: the language specification does not define where values are stored, and engines may keep small values in registers or inline in objects. The reliable rule is behavioural: primitives behave as immutable values, and objects behave as shared references.

Freezing objects

Objects are mutable by default, but you can restrict that:

javascript
javascript
Loading syntax highlighting...

Object.freeze is shallow, so nested objects stay mutable unless you freeze them too. Using const only prevents reassigning the variable, not changing the object.

Detecting object types in practice

Because typeof reports "object" for most non-primitives, combine checks when you need to be precise:

javascript
javascript
Loading syntax highlighting...

This helper returns true for every non-primitive value and false for every primitive, which is exactly the split the question is about.

Frequently Asked Questions

Is an array primitive in JavaScript?

No. An array is an object with numeric keys and a length property, so it is non-primitive.

Is a function a primitive?

No. Functions are callable objects and can have properties, which is why they can be passed around like any other value.

Is null primitive even though typeof says object?

Yes. typeof null === "object" is a historic quirk. null is a primitive value, and you should test it with value === null.

Is a string an object?

A string value is a primitive. A new String("abc") wrapper is an object, and you should avoid creating wrappers like that.

Summary

  • Object is the only non-primitive data type, and arrays, functions, dates, regex, maps and sets are objects.
  • Primitives are immutable and compared by value, while objects are mutable and compared by reference.
  • Use Array.isArray() and === null where typeof is ambiguous.
  • Copy objects deliberately with spread or structuredClone.
Share