This is the 16th day of my participation in the August More Text Challenge. For details, see:August is more challenging

preface

Hello everyone, today to record the number of javascript, the content of the main reference “You don’t know javascript” (volume), at the same time will add their own thinking, as well as practice examples, it is said that a good memory is not as good as bad writing, reading the book must be frequently take notes, so not only remember firmly, but also to improve their level.

The body of the

Note in advance oh, this is a front note type article, belongs to personal record. Please take a detour not to spray, thank you ~

digital

JavaScript uses a “double precision” format (that is, 64-bit binary)

You can leave out the 0 before the digit and the 0 at the end of the decimal place. Such as:

0.42 ===.42 // true 42.30 === 42.3 // trueCopy the code

Very large and very small numbers are displayed in an exponential format by default, the same as the output of the toExponential() function.

let a = 5E10  // 50000000000
a.toExponential()  // "5e+10"
let c = 1/a  // "2e-11"
Copy the code

The. Operator is first treated as part of the number and then accessed as an object property

Such as:

1. ToFiexd (2) // 100.00 (100). ToFixed (2) // 100.00 (100). ToFixed (2) / / 100.00Copy the code

That is, if it is legal to include. In the next number, it will be considered part of the number


Floating point precision, can be used to solve the error value range, avoid 0.1+0.2! == 0.3.

Error range is to set a value of error range, two numbers are subtracted from the result is less than this value is determined to be equal.

EPSILON = math.pow (2,-52).EPSILON = math.pow (2,-52).

The maximum floating point Number of js is about 1.798e+308, defined in number.max_value.

The minimum js floating point Number is about 5e-324, defined in number.min_value, which is infinitely close to 0.

The maximum safe range for an integer is 2^ 54-1, or 9007199254740991, defined in ES6 as number. MAX_SAFE_INTEGER

The minimum safe range for integers is -9007199254740991, defined in ES6 as number.min_safe_INTEGER

Numbers that exceed a certain number of digits should be represented as strings, such as multi-digit ids.

Check the integer: number.isINTEGER (num), return true or false, equivalent to:

typeof num == 'number' && num%1 == 0
Copy the code

Checks for a safe range integer: number.issafeINTEGER (num), returns true or false, equivalent to:

Number.isInteger(num) && Math.abs(num) <= Number.Max_SAFE_INTEGER
Copy the code

Null: a null value (once assigned but now has no value). It is a special keyword and cannot be used or assigned as a variable

Undefined: has no value (never assigned), is an identifier, can be used as a variable or assigned (only local variables can be declared undefined in strict mode), redefining undefined is not a good idea.

Void allows an expression to return no value. For example, void XXX results in undefined.

The special numerical

NaN: a number that is not a number, but is still of numeric type, and is the only non-reflexives value in JS, namely: NaN! = NaN

You can use isNaN() to determine if a value isNaN, but isNaN has a bug. It only determines if the argument is neither NaN nor a number

In ES6 we should use number.isnan () to determine NaN, which is equivalent to:

typeof(n) === "number" && windows.isNaN(n)
Copy the code

It would be easier to determine if the value is not equal to itself, since NaN is the only non-reflexive value in JS

Infinite Number: js uses finite Number representation, when the result of js operation exceeds the processing range, the nearest integer is number. MAX_VALUE or Number_MIN_VALUE, if overflow (the Number range of JS), the result is Infinity or -infinity.

Infinite numbers can be obtained from finite numbers, but infinite numbers cannot be obtained from finite numbers.

Zero value: js has 0 and -0. Converting a number to -0 returns ‘0’, but converting a string to a number to ‘-0’ returns -0

0 === -0 // true

ES6’s new object.is () method handles the comparison of special values to determine whether two values are absolutely equal, and can be used to determine NaN and -0 cases

Object.is(NaN,NaN)  // true
Object.is(0,-0) // false
Copy the code

Afterword.

Hello wow, I am the Antarctic ice, a technology and appearance level is proportional to the front end of the engineer, advocating to nail down the front end of the problem, I hope my blog has helped you.

Pay attention to me, the front road together. Hey ~ 😛