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
trueif the provided value is an integer. Otherwise,falsewill be returned. -
For floating-point numbers that can be represented as integers,
truewill be returned. For the value5.0, we gettrueas a result. -
For the argument which is not a type of number,
falseis returned. For the String value'5', we getfalseas a result.
Please note:
falsewill be returned forNaNandInfinity.
Code example
The code demonstrates how to use the isInteger method in Lodash:
Code explanation
In the above code:
-
Line 6: We loaded the
Lodashlibrary file from the server link. -
Line 10: We used the
isIntegermethod to check if the numeric value1is an integer. We gettrueas a result. -
Line 13: We used the
isIntegermethod to check if the float value10.0is an integer. The value10.0can be represented as an integer, sotrueis returned as a result. -
Line 16: We used the
isIntegermethod to check if the float value10.1is an integer. The value10.1cannot be represented as an integer, sofalseis returned as a result. -
Line 19: We used the
isIntegermethod to check if the string value'1'is an integer. The value'1'is a string and not a numeric type, sofalseis returned. -
Line 22: We used the
isIntegermethod to check if the valueNaNis an integer. TheisIntegermethod will returnfalseforNaN.