6. The value of expansion

Extended value

A standardized method .Number

  1. In ES6, in order to reduce the overall method, the progressive modular, so figures for a method to transplant the object Number

    • Number.isNaN (): determining whether non-numeric
    • Number.isFinite (): determines whether the value is limited
    • Number.parseInt (): converts a number to an integer
    • Number.parseFloat (): converts a number to float
  2. In conventional in JavaScript, and isFinite isNaN string can be converted into a digital registration parameters, and then determining

    isNaN("123");    //false
    isNaN(123);      //false
    isNaN('NaN');    //true
    
    isFinite('25')   //true
  3. Number of objects in ES6

    • The difference is that the conventional method, and isFinite isNaN does not convert a string value, and then determines do

    • isNaN is a number of parameters they do not, all returns false

    • isFinite parameter value is not as long, all returns false

      isNaN(NaN);                //true
      isNaN('NaN');          //true
      Number.isNaN(NaN);     //true
      Number.isNaN('NaN');   //false
      
      isFinite('88');            //true
      isFinite(88);          //true
      Number.isFinite('88'); //false
      number.isFinite(88);   //true
  4. For consistency parseInt and parseFloat methods and traditional methods

.Number two new methods

  1. Number.isInteger()

    • It used to determine whether the number is an integer

    • If the parameter value is not directly returns false

    • Note: decimal floating point numbers 0, that is considered to be an integer

      Number.isInteger('25');        //false
      Number.isInteger(25.0);        //true
      Number.isInteger(25.5);        //fasle
      Number.isInteger(25);      //true
  2. Number.isSafeInteger()

    • JavaScript can be prepared to represent between -2 ^ 53 to 2 ^ 53, outside this range can not be accurately represents the value
    • ES6 added Number.MAX_SAFE_INTEGER and MIN_SAFE_INTEGER two constants used to represent this range
    • I.e. Number.isSafeInteger method is used to determine whether the currently given number within this range
  3. Number.EPSILON

    • Number ES6 the above, add a very small constant
    • This variable is essentially a minimum acceptable error range
    • If the two floating-point interpolation less than this value, we can consider two floating point numbers are equal

Extended three .Math object

ES6 Add as a 17 Math object methods related to mathematics, pick a few commonly used here, a brief introduction

  1. Math.trunc () : used to remove the fractional portion of a number
  2. Math.sign () : number is used to determine a positive number (1), negative (-1) or 0 (0)
  3. ... Specifically, we are needed, in particular to understand

to sum up

  1. ES6 some numerical processing method to transplant Number object, in order to gradually modular, reducing the overall process
    • Number.isNaN()
    • Number.isFinite()
    • Number.parseInt()
    • Number.parseFloat()
  2. ES6 added some method for the Number object,
    • Number.isInteger (): determines whether the value is an integer
    • Number.isSafeInteger (): determines whether the value is an integer in the range of safe
    • Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER two constants used to represent the maximum and minimum number of safety
    • Number.EPSILON: it is used to represent a very small constant representing the minimum error range calculation between the float
  3. ES6 added 17 for the Math methods related to mathematics, when used in specific circumstances, you can go inquiry

Guess you like

Origin www.cnblogs.com/mapengfei247/p/11105057.html