# Check if a Number is a Positive Integer in JavaScript Sun Oct 17 20212 min read Photo by Joshua Earle

## Check if a Number is a Positive Integer#

To check if a number is a positive integer:

1. Pass the number to the `Number.isInteger()` method. The method returns `true` if the provided value is an integer and `false` otherwise.
2. Check that the number is greater than `0`.
3. If both conditions are met, the number is a positive integer.
index.js
```Copied!```function isPositiveInteger(value) {
if (Number.isInteger(value) && value > 0) {
return true;
}

return false;
}

console.log(isPositiveInteger(1)); // 👉️ true
console.log(isPositiveInteger(0)); // 👉️ false
console.log(isPositiveInteger(1.5)); // 👉️ false
console.log(isPositiveInteger(-1)); // 👉️ false
console.log(isPositiveInteger('1')); // false
``````

We used the Number.isInteger method to determine if the passed in value is an integer or not.

The method returns `true` if the value is an integer and `false` otherwise.

Here are some examples of using the `Number.isInteger` method directly.

index.js
```Copied!```console.log(Number.isInteger(5)); // 👉️ true
console.log(Number.isInteger(5.5)); // 👉️ false
console.log(Number.isInteger('5')); // 👉️ false
console.log(Number.isInteger(-5)); // 👉️ true
``````

We then used the logical AND (&&) operator to chain another condition.

For the `if` block to run both conditions have to be met.

The second condition is only evaluated if the first condition returns `true`.

In our second condition, we check if the integer is greater than `0`. If the value is an integer and it's greater than `0`, then it's a positive integer.

However, there is a caveat with the `Number.isInteger` method. The method returns `true` if the passed in value:

• is an integer
• is a float, that can be represented as an integer

Here are examples of floats that can be represented as integers:

index.js
```Copied!```// 👇️ true
console.log(Number.isInteger(10.0));

// 👇️ true
console.log(Number.isInteger(10.000000000000000123));
``````

It depends on your use case, however most applications are ok with considering numbers such as `5.0` and `3.0` to be integers. 