mozilla
Your Search Results

    Number.isSafeInteger()

    This is an experimental technology, part of the ECMAScript 6 (Harmony) proposal.
    Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future version of browsers as the spec changes.

    Summary

    The Number.isSafeInteger() method determines whether the provided value is a number that is a safe integer. A safe integer is an integer that

    • can be exactly represented as an IEEE-754 double precision number, and
    • whose IEEE-754 representation cannot be the result of rounding any other integer to fit the IEEE-754 representation.

    For example, 253 - 1 is a safe integer: it can be exactly represented, and no other integer rounds to it under any IEEE-754 rounding mode. In contrast, 253 is not a safe integer: it can be exactly represented in IEEE-754, but the integer 253 + 1 can't be directly represented in IEEE-754 but instead rounds to 253 under round-to-nearest and round-to-zero rounding.

    The safe integers consist of all integers from -(253 - 1) inclusive to 253 - 1 inclusive.

    Syntax

    Number.isSafeInteger(testValue)

    Parameters

    testValue
    The value to be tested for being a safe integer.

    Examples

    Number.isSafeInteger(3);                    // true
    Number.isSafeInteger(Math.pow(2, 53));      // false
    Number.isSafeInteger(Math.pow(2, 53) - 1);  // true
    Number.isSafeInteger(NaN);                  // false
    Number.isSafeInteger(Infinity);             // false
    Number.isSafeInteger('3');                  // false
    Number.isSafeInteger(3.1);                  // false
    Number.isSafeInteger(3.0);                  // true
    

    Specifications

    Specification Status Comment

    ECMAScript 6 (ECMA-262)
    The definition of 'Number.isSafeInteger' in that specification.

    Release Candidate Initial definition.

    Browser compatibility

    Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
    Basic support (Yes) 32 (32) Not supported (Yes) Not supported
    Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
    Basic support Not supported Not supported 32.0 (32) Not supported Not supported Not supported

    See also

    Document Tags and Contributors

    Contributors to this page: ziyunfei, Mingun, Waldo, fscholz, realityking
    Last updated by: Mingun,