Back to Functions

isBoolean

lang

Checks if value is classified as a Boolean primitive or object.

Installation

Import
import { isBoolean } from '@tulx/utils';

Source Code

Implementation
/**
 * Checks if value is classified as a Boolean primitive or object.
 *
 * @param value - The value to check.
 * @returns Returns true if value is a boolean, else false.
 *
 * @example
 * ```ts
 * isBoolean(false); // true
 * isBoolean(null); // false
 * ```
 */
export function isBoolean(value: unknown): value is boolean {
  return typeof value === 'boolean' || value instanceof Boolean;
}

Example

import { isBoolean } from '@tulx/utils';

isBoolean(false); // true
isBoolean(null); // false

Related Functions