Skip to content

isNumber

Import from @varavel/vdl-plugin-sdk/utils/predicates.

function isNumber(x): x is number;

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.

Parameters

Parameter Type Description
x unknown The value to test if it is a number.

Returns

x is number

True if the value is a number, false otherwise.

Example

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

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