1.38.0isBoolean
Checks whether a value is a boolean and provides a TypeScript type guard for boolean narrowing.
isBoolean(value):value is booleanImplementation
The function uses JavaScript's typeof operator and checks whether the result is exactly "boolean".
Type guard
The return type `value is boolean` makes the function a TypeScript type guard. When the function returns true, TypeScript can narrow the checked value to boolean.
Boolean primitive
The function recognizes only the boolean primitive values true and false. Boolean wrapper objects are not recognized as boolean values.
Parameters
valueunknownrequiredThe value to check.
Returns
value is booleanReturns true when the value is a boolean; otherwise returns false. When true, TypeScript narrows the value to boolean.
Examples
Basic usage
Check whether a value is a boolean.
isBoolean(true);
// true
isBoolean(false);
// true
isBoolean("true");
// falseType narrowing
The type guard narrows an unknown value to boolean inside the conditional block.
const value: unknown = true;
if (isBoolean(value)) {
value.valueOf();
// value is narrowed to boolean
}Other primitive values
Numbers, strings, null, undefined, and objects are not considered booleans.
isBoolean(1);
// false
isBoolean("false");
// false
isBoolean(null);
// false
isBoolean(undefined);
// false
isBoolean({});
// falseBoolean objects
A Boolean object is not considered a boolean primitive because typeof returns "object".
isBoolean(new Boolean(true));
// false