What is the isInteger() method in Lodash?

Overview

The isInteger method can check if a value is an integer value or not.

Syntax

The syntax of the isInteger() method is given below.

_.isInteger(value)

Parameter

This method takes the value to be tested for an integer.

Return value

  • This method returns true if the provided value is an integer. Otherwise, false will be returned.

  • For floating-point numbers that can be represented as integers, true will be returned. For the value 5.0, we get true as a result.

  • For the argument which is not a type of number, false is returned. For the String value '5', we get false as a result.

Please note: false will be returned for NaN and Infinity.

Code example

The code demonstrates how to use the isInteger method in Lodash:

Console
Using the isInteger method

Code explanation

In the above code:

  • Line 6: We loaded the Lodash library file from the server link.

  • Line 10: We used the isInteger method to check if the numeric value 1 is an integer. We get true as a result.

  • Line 13: We used the isInteger method to check if the float value 10.0 is an integer. The value 10.0 can be represented as an integer, so true is returned as a result.

  • Line 16: We used the isInteger method to check if the float value 10.1 is an integer. The value 10.1 cannot be represented as an integer, so false is returned as a result.

  • Line 19: We used the isInteger method to check if the string value '1' is an integer. The value '1' is a string and not a numeric type, so false is returned.

  • Line 22: We used the isInteger method to check if the value NaN is an integer. The isInteger method will return false for NaN.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources