es-toolkit
Version:
A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.
29 lines (28 loc) • 809 B
JavaScript
//#region src/compat/predicate/isBoolean.ts
/**
* Checks if the given value is boolean.
*
* This function tests whether the provided value is strictly `boolean`.
* It returns `true` if the value is `boolean`, and `false` otherwise.
*
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `boolean`.
*
* @param value - The Value to test if it is boolean.
* @returns True if the value is boolean, false otherwise.
*
* @example
*
* const value1 = true;
* const value2 = 0;
* const value3 = 'abc';
*
* console.log(isBoolean(value1)); // true
* console.log(isBoolean(value2)); // false
* console.log(isBoolean(value3)); // false
*
*/
function isBoolean(value) {
return typeof value === "boolean" || value instanceof Boolean;
}
//#endregion
export { isBoolean };