Design & Download
Your JS Library
in Seconds!!!

Snippet: isSafeInt() ES6 Style

Written by Christopher West (cwest) on November 29, 2015.
Determines if the argument that is passed in is an integer in the range of -9007199254740991 and 9007199254740991.
function isSafeInt(value) {
  return typeOf(value, 'Number') && value % 1 == 0 && Math.abs(value) <= (Math.pow(2,53) - 1);
}

isSafeInt() API Documentation

Description

Determines if the argument that is passed in is an integer in the range of -253+1 and 253-1.

Parameters

  1. value {number}:
    The value to be tested to see if it is an integer in the range of -253+1 and 253-1.

Returns

Returns true if value is an integer within the range of -253+1 and 253-1. In all other cases false is returned.