Skip to content

Latest commit

 

History

History
36 lines (25 loc) · 796 Bytes

prefer-number-is-integer.md

File metadata and controls

36 lines (25 loc) · 796 Bytes

Prefer Number.isInteger() for integer checking

Enforces the use of Number.isInteger() for checking if a number is an integer.

These different implementations have slightly different behaviors.

For example:

let number = [['1']];

number % 1 === 0; // true

Due to the difference in behaviours across the different implementations, this rule is fixable via the suggestions API.

Fail

(value^0) === value
(value | 0) === value
Math.round(value) === value
parseInt(value, 10) === value
~~value === value

// These will all trigger the lint warning
_.isInteger(value);
lodash.isInteger(value);
underscore.isInteger(value);

Pass

Number.isInteger(value);