This is the 10th day of my participation in Gwen Challenge
1. What is the safe range of integers in js
A safe integer is an integer in this range that can be converted to binary storage without loss of precision. The maximum integer that can be safely rendered is 2^ 53-1, that is, 9007199254740991, defined as number. MAX_SAFE_INTEGER in ES6. The minimum integer is -9007199254740991, which is defined as number.min_safe_INTEGER in ES6.
If a calculation results in a value that is outside the JavaScript value range, the value is automatically converted to a special Infinity value. If one calculation returns a positive or negative Infinity value, that value will not participate in the next calculation. To determine whether a number isFinite, use the isFinite function.
2. What is the result of typeof NaN?
NaN means “not a number,” and NaN is a sentinel value (a general value for a special purpose) used to indicate an error situation in a number type, that is, “the result of a failure to perform a mathematical operation.”
typeof NaN; // “number”
NaN is a special value that is not equal to itself and is the only value that is not reflexive (that is, x === x is not valid). NaN! = NaN is true.
3. IsNaN and Number. IsNaN functions?
The function isNaN takes an argument and tries to convert it to a value. Any value that can’t be converted to a value returns true, so non-numeric values also return true, affecting NaN’s judgment.
The function number. isNaN determines whether the argument passed is a Number first, and if it is a Number then whether it is a NaN, which is more accurate for NaN.
4. How does the Array constructor behave when it has only one parameter?
When the Array constructor takes only one numeric argument, that argument is used as the default length of the Array, rather than as an element in the Array. This creates an empty array with its length property set to the specified value.
Constructor Array(..) The new keyword is not required. If not, it will be automatically replaced.
5. Conversion rules for other values to strings?
Section 9.8 of the specification defines the abstract operation ToString, which handles non-string-to-string casts.
(1) Null and Undefined, Null to “Null”, Undefined to “Undefined”,
(2) Boolean, true to “true”, false to “false”.
(3) The value of type Number is converted directly, but the very small and the very large numbers are used in exponential form.
(4) The value of Symbol type is directly converted, but only explicit casts are allowed. Using implicit casts will cause errors.
(5) for ordinary objects defined unless the toString () method, or you will call the toString () (Object. The prototype. The toString () to return the internal properties of [[Class]] value, such as “[Object Object]”. If an object has its own toString() method, that method is called and its return value is used when stringified.
6. Conversion rules for other values to numeric values?
Sometimes we need to treat non-numeric values as numbers, such as math operations. For this purpose, the ES5 specification defines the abstract operation ToNumber in Section 9.3.
(1) The value of Undefined is converted to NaN.
(2) A value of Null type is converted to 0.
Boolean values, true to 1 and false to 0.
(4) String values are converted as if using the Number() function. If it contains a non-numeric value, it is converted to NaN and the empty String is 0.
(5) The value of Symbol type cannot be converted to numbers, and an error will be reported.
(6) Objects (including arrays) are first converted to the corresponding primitive type value. If a non-numeric primitive type value is returned, it is then cast to a number following the above rules.
In order to convert a value to the corresponding primitive type value, the abstract operation ToPrimitive first checks (through the internal operation DefaultValue) whether the value has a valueOf() method. If a primitive type value is present and returned, that value is used for the cast. If not, the return value of toString() is used (if present) for the cast.
If neither valueOf() nor toString() returns a base type value, TypeError is generated.
7. Conversion rules for other values to Boolean values?
The abstract operation ToBoolean, defined in Section 9.2 of the ES5 specification, lists all possible results of a Boolean cast.
These are false values:
- undefined
- null
- false
- +0, -0, and NaN
- “”
A false Boolean cast results in false. Logically, anything outside the list of false values should be true.
8. What are the results of valueOf and toString for {} and []?
ValueOf of {} is {}, toString is “[object object]”
ValueOf for [] is [], and toString is “”
9. Talk about your understanding of This object.
This is an attribute in the execution context that points to the object on which the method was last called. In real development, the direction of this can be determined by four invocation patterns.
-
The first is the function call pattern, where this refers to the global object when a function is called directly as a function that is not a property of an object.
-
The second is the method invocation pattern, where if a function is called as a method of an object, this refers to that object.
-
The third is the constructor invocation pattern. If a function is called with new, a new object is created before the function is executed. This refers to the newly created object.
-
The fourth is the apply, call, and bind call modes, all of which can display the this pointer to the specified calling function. The apply method takes two parameters: an object bound to this and an array of parameters. The call method receives arguments, the first of which is the object of the this binding, followed by the remaining arguments passed into the function to execute. That is, when using the call() method, the arguments passed to the function must be enumerated one by one. The bind method returns a new function that binds the object to this by passing it in. The this pointer to this function does not change except when new is used.
What do you know about JSON?
JSON is a data interchange format, text-based, superior to lightweight, for exchanging data.
JSON can represent numbers, booleans, strings, NULL, arrays (ordered sequences of values), and objects made up of these values (or arrays, objects) (mappings between strings and values).
JSON uses JavaScript syntax, but the JSON format is just text. Text can be read by any programming language and passed as a data format.