Skip to content

isPrimitive

Import from @varavel/vdl-plugin-sdk/utils/predicates.

function isPrimitive(value): value is string | number | bigint | boolean | symbol | null | undefined;

Checks whether a value is a JavaScript primitive. JavaScript primitives include null, undefined, strings, numbers, booleans, symbols, and bigints.

Parameters

Parameter Type Description
value unknown The value to check.

Returns

value is string | number | bigint | boolean | symbol | null | undefined

Returns true if value is a primitive, false otherwise.

Example

isPrimitive(null); // true
isPrimitive(undefined); // true
isPrimitive('123'); // true
isPrimitive(false); // true
isPrimitive(true); // true
isPrimitive(Symbol('a')); // true
isPrimitive(123n); // true
isPrimitive({}); // false
isPrimitive(new Date()); // false
isPrimitive(new Map()); // false
isPrimitive(new Set()); // false
isPrimitive([1, 2, 3]); // false