JavaScript .isInteger()

ramanLamichhane8756805339's avatar
Published Oct 12, 2021Updated Oct 13, 2021

The Number.isInteger() method is a part of the Number class in JavaScript.

It accepts a single argument, value, and returns true if the passed argument is an integer, and returns false otherwise.

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours

Syntax

Number.isInteger(value);
  • value (required): The value to check.

Examples

To verify if a value is an integer or not:

const x = 13 / 5;
// x = 2.6
console.log(Number.isInteger(x));
// Output: false
const y = 10 / 5;
// y = 2
console.log(Number.isInteger(y));
// Output: true

The above example passes an integer and a decimal value into Number.isInteger() method, to verify if the value is an integer or not. Then, the result is printed.

Codebyte Example

Code
Output

All contributors

Learn JavaScript on Codecademy

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours