Do something if a number is an integer in JavaScript

To make an if statement that is checking whether the number is an integer or not, just use the Number.isInteger() method.

<script>
    if(Number.isInteger(yourNumber)) {
        // do something
    }
</script>

Example:

<script>
    var variable1 = 5; // integer
    var variable2 = 'hello'; // string
    var variable3 = 5.20; // float

    if(Number.isInteger(variable1)) {
        console.log(variable1);
    } else {
        console.log('variable1 is not an integer');
    }
    // Output (console): 5

    if(Number.isInteger(variable2)) {
        console.log(variable2);
    } else {
        console.log('variable2 is not an integer');
    }

    // Output (console): variable2 is not an integer

    if(Number.isInteger(variable3)) {
        console.log(variable3);
    } else {
        console.log('variable3 is not an integer');
    }

    // Output (console): variable3 is not an integer
</script>