CyrefJS
CCyrefJS
فا
Back to documentation
Validation/Since 1.38.0

isPositive

Checks whether a value is a positive number.

isPositive(value):boolean

Behavior

The function first checks that the value type is number, then verifies that it is greater than zero.

Zero Handling

Zero is not considered positive because the comparison uses value > 0.

Type guard

The function narrows unknown values to number when it returns true.

Parameters

valueunknownrequired

The value to check.

Returns

boolean

Returns true when the value is a number greater than zero; otherwise returns false.

Examples

01

Positive numbers

Returns true for numbers greater than zero.

TypeScript
isPositive(10);
// true

isPositive(0.5);
// true
02

Zero and negative numbers

Zero and negative numbers are not considered positive.

TypeScript
isPositive(0);
// false

isPositive(-5);
// false
03

Non-number values

Non-number values return false.

TypeScript
isPositive("10");
// false

isPositive(null);
// false

isPositive(true);
// false
04

Special numbers

NaN and Infinity behavior follows JavaScript number comparisons.

TypeScript
isPositive(NaN);
// false

isPositive(Infinity);
// true
Built with@cyref/js·Official documentation