Принуждение 1
typeof NaN >>> “number”
Пояснения:
By definition, NaN is the return value from operations which have an undefined * numerical result. Hence why, in JavaScript, aside from being part of the global Object, it is also part of the Number object: Number.NaN. It is still a Numeric data type, but it is undefined as a real number
Примеры
Number.MAX_VALUE >> 1.7976931348623157e+308 console.dir(Number) > get more info about Number typeof (3.2317006071311 * 10e616) / (3.2317006071311 * 10e616)
Примечание. Не используйте (typeof NaN), а используйте (isNan())
Дополнительная информация: https://javascriptrefined.io/nan-and-typeof-36cd6e2a4e43
Принуждение 2
9999999999999999 >>> 10000000000000000
Пояснения:
That number is too large to fit in an integer, so is possibly converted to a double. Floating point numbers are not exact. All javascript numbers are double precision floating point numbers, that means you have only 16 digit of precision, and 9999999999999999 clearly passes that limit
Принуждение 3
0.2 + 0.1 === 0.3 >>> false
Пояснения:
Actually 0.2+0.1 === 0.3 gives you 0.30000000000000004 The length of 0.30000000000000004 is 19 and it will be converted into (double only has 15/16 digits of accuracy and when you give it a number it can’t represent (which is most of the time, even 0.1 is not accurate) it takes the closest representable number.)
Примечание. Числа с плавающей запятой не точны
Принуждение 4
Math.max() >>> -Infinity and Math.min() >> Infinity
Пояснения:
The Math.max() function is used to return the largest of zero or more numbers. The result is “-Infinity” if no arguments are passed and the result is NaN if At least one of the arguments cannot be converted to a number. max() is a static method of Math, therefore, it is always used as Math.max() Rather than as a method of a Math object created.
Принуждение 5
[]+[] >>> “”
{}+[] >>> 0
[]+{} >>> “[object Object]”
Пояснения:
All operands are non-primitive values, so + starts with the leftmost triggering Numeric conversion. Both Object’s and Array’s valueOf method returns the object Itself, so it’s ignored. toString() is used as a fallback. The trick here is That first {} is not considered as an object literal, but rather as a block declaration statement, so it’s ignored. Evaluation starts with next +[ expression, which is converted to an empty string via toString() method and then to 0.
Принуждение 6
true + true + true === 3 >>> true
Пояснения:
true >>> 1 false >>> 0 When you are trying to make + operation true is like 1 and false is like 0. Then if you make true+true+true you get 3