Skip to content

isPrimitive

Checks if a value is a JavaScript primitive.

Primitive types: string, number, boolean, bigint, symbol, null, undefined.

Available since v2.0.0

import { isPrimitive } from '@helpers4/guard';
isPrimitive(value: unknown): value is Primitive
ParameterTypeDescription
valueunknownThe value to check

value is Primitive — True if value is a primitive

isPrimitive('hello')  // => true
isPrimitive(42)       // => true
isPrimitive(null)     // => true
isPrimitive({})       // => false
isPrimitive([])       // => false

Union of all JavaScript primitive types.

type Primitive = string | number | boolean | bigint | symbol | null | undefined

View source on GitHub