Type/Since
1.38.0isObject
Checks whether a value is a non-null JavaScript object.
isObject(value):value is objectBehavior
The function first excludes null, then checks whether typeof value is object. Because of this, arrays and built-in object instances such as Date, Map, and Set also return true.
Null Handling
Although typeof null returns object in JavaScript, the function explicitly excludes null by checking value !== null.
Type Guard
The return type is value is object, allowing TypeScript to narrow the value to object inside a conditional branch.
Parameters
valueunknownrequiredThe value to check.
Returns
value is objectReturns true when the value is not null and its typeof result is object; otherwise, returns false.
Examples
01
Basic usage
Check whether different values are objects.
TypeScript
import { isObject } from "@cyref/js";
isObject({});
// true
isObject([]);
// true
isObject(new Date());
// true
isObject(null);
// false
isObject("hello");
// false
isObject(42);
// false02
Type narrowing
isObject acts as a TypeScript type guard and narrows the value to object when it returns true.
TypeScript
const value: string | object = {};
if (isObject(value)) {
// value is object
}Built with@cyref/js·Official documentation