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