es-toolkit/docs/reference/predicate/isBoolean.md
2024-08-08 18:47:50 +09:00

613 B

isBoolean

Checks if the given value is a boolean.

This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to boolean.

Signature

function isBoolean(x: unknown): x is boolean;

Parameters

  • x (unknown): The value to test if it is boolean.

Returns

(x is boolean): True if the value is boolean, false otherwise.

Examples

const value1 = true;
const value2 = 0;
const value3 = 'abc';

console.log(isBoolean(value1)); // true
console.log(isBoolean(value2)); // false
console.log(isBoolean(value3)); // false