jskatas.org Continuously Learn JavaScript. Your Way.

Number API: Number.isInteger()

Number.isInteger() determines if a value is an integer.

Donate to NGO Julenka. Support Ukranians in need. Julenka is an NGO which my brother founded in 2011 to support Ukranian families and kids in need.

The function Number.isInteger()

  • is a static function on Number

handles zero in different ways

  • the literal 0 is an integer
  • the float value 0.000 is also an integer
  • the string 0 is NOT an integer

also sees the number 1 in different ways

  • the sum of 0.01 and 0.99 is an integer
  • the sum of 0.5 + 0.6 is NOT an integer
  • the result of parseInt("1") is an integer
  • the string "1" is NOT an integer

identifies many things NOT as integer

  • Number() (which returns a 0) is an integer
  • the object literal {} is NOT an integer
  • the float value 0.1 is not an integer
  • Number.Infinity is not an integer
  • NaN is also not an integer