Skip to main content
isPrimitive - util - Node documentation
function isPrimitive

Usage in Deno

import { isPrimitive } from "node:util";
isPrimitive(object: unknown): boolean
Deprecated

Since v4.0.0 - Use (typeof value !== 'object' && typeof value !== 'function') || value === null instead.

Returns true if the given object is a primitive type. Otherwise, returnsfalse.

import util from 'node:util';

util.isPrimitive(5);
// Returns: true
util.isPrimitive('foo');
// Returns: true
util.isPrimitive(false);
// Returns: true
util.isPrimitive(null);
// Returns: true
util.isPrimitive(undefined);
// Returns: true
util.isPrimitive({});
// Returns: false
util.isPrimitive(() => {});
// Returns: false
util.isPrimitive(/^$/);
// Returns: false
util.isPrimitive(new Date());
// Returns: false

Parameters

object: unknown

Return Type

boolean