How to Check if a Number Is a Whole Number in JavaScript with Number.isInteger
Number.isInteger(value) gives true when the value is a number with no fractional part, such as 500, and false for anything else, including the string '500'. It doesn't convert its argument, so it also tells you the value really is a number.
Syntax
Number.isInteger(<value>)
| Part | What it does |
|---|---|
Number.isInteger | A static method of Number: you call it on Number itself. |
<value> | Any value. Anything that isn't a number gives false, and it never throws. |
MDN's Number.isInteger reference: "If the target value is an integer, return true, otherwise return false. If the value is NaN or Infinity, return false."
The Example
The example checks 500, 500.0, 500.5, the string '500', NaN and Infinity.
Prerequisites
- Node.js. This guide uses Node.js 26.13.1.
Step 1: Write the Code
Create a file named main.js:

console.log(Number.isInteger(500));
console.log(Number.isInteger(500.0));
console.log(Number.isInteger(500.5));
console.log(Number.isInteger('500'));
console.log(Number.isInteger(NaN));
console.log(Number.isInteger(Infinity));
Step 2: Run It
node main.js
true
true
false
false
false
false

The command is the same in zsh, bash and PowerShell.
What Happened
500istrue, a whole number.500.0istrueas well. JavaScript has one number type, and500.0is the same number as500.500.5isfalse: it has a fractional part.- The string
'500'isfalse.Number.isIntegerdoesn't convert strings, so text that looks like a number doesn't pass. NaNandInfinityarefalse, even thoughtypeofsays both are numbers.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Expecting '500' from a form or a URL to pass | It's a string, so the check fails | Convert it first: Number.isInteger(Number('500')) is true |
Calling isInteger(5) on its own | ReferenceError: isInteger is not defined | Call it on Number: Number.isInteger(5) |
Using typeof value === 'number' to mean "a usable whole number" | 500.5, NaN and Infinity pass too | Use Number.isInteger(value) |
Checking a BigInt such as 10n | false: a BigInt isn't a number | Check with typeof value === 'bigint' |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
A number you typed with decimals passes, such as 5.0000000000000001 | That many digits are beyond what a JavaScript number holds, so it's stored as 5 | Round or validate the input as text first |
| Huge numbers pass, but arithmetic on them is wrong | Above 2 ** 53, numbers can't hold every whole value | Use Number.isSafeInteger |
FAQ
What's the difference between Number.isInteger and Number.isSafeInteger?
Number.isSafeInteger also requires the number to be small enough to be exact. Number.isInteger(2 ** 53) is true, but Number.isSafeInteger(2 ** 53) is false.
Does Number.isInteger accept negative numbers?
Yes. Any whole number counts, negative ones and 0 included.
Conclusion
Number.isInteger is a one-call check that a value is a real number with no fractional part. Convert input from text first, and use Number.isSafeInteger when the number must also be exact.
Additional Resources
- Number.isInteger(), on MDN.
- Number.isSafeInteger(), on MDN.
