Skip to content

isObject

isObject(value): value is object

Defined in: packages/core/src/guards/is-object.ts:35

Check whether a value is a non-null object that is not an array.

A function never passes: typeof reports it as "function", not "object". Everything else non-primitive does — a Date, a Map, a Promise, a class instance, an Object.create(null) bag.

Reach for it when the next thing you do is read a property off the value and an array would take a different branch. It answers “is there an object here”, not “is this object a data bag”.

The family, from loosest to strictest:

  • isObject — any non-null, non-array object, whatever built it.
  • isPojo — narrows to Record<string, unknown>; rejects a Date, a Map and a class instance, whose prototype chain does not reach Object.prototype. Use it before merging, cloning or deep-comparing, where walking a Date’s own keys would silently drop its value.
  • hasObjectPrototype — the same question asked of the own prototype only, so Object.create({}) fails where isPojo passes. Use it when the answer decides how a value is rebuilt, not just how it is read.

unknown

The value to check

value is object

True if the value is a non-array object

isObject({}); // true
isObject(new Date()); // true
isObject([]); // false
isObject(null); // false
isObject(() => {}); // false
```;