Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • 2
    MDN has the test on 9007199254740992 removed Commented Jul 30, 2015 at 10:43
  • 6
    This is the most straightforward and "correct" answer. I mean, JavaScript already has the method to check for integerhood. No need to write a new one. isNaN() tests for numericity, not integerhood. Commented Jan 29, 2019 at 16:28
  • 4
    @globewalldesk Maybe it answers the question "how to check if a number is integer" but not "if a variable is integer". E.g. a string "1" for example. Commented Nov 12, 2020 at 11:52
  • 1
    I find it useful to do Number.isInteger(parseFloat(value)) for form validations. Things magically change from number to string and back sometimes when dealing with forms. Commented Mar 25, 2021 at 22:28
  • 2
    @WalterRoman parseInt('123abc') will become 123, thus invalidating your method. Commented Jan 15, 2023 at 0:08