Check if a value is an integer

There are a few different ways you can determine if a value is an integer in JavaScript. ECMAScript6 provides a direct <a href="">isInteger</a> method, but for current browsers you can apply a few different methods. The simplest is to compare the result of Math.round to the original value. Using triple equality checking also handles non-numbers as well.

function isInteger(x) {
    return Math.round(x) === x;

Author: Dr. Axel Rauschmayer
Tags: math

comments powered by Disqus