Q3: How is the data type detected? What are the ways? What is the principle?
Typyof detects the base data type , thereturn value is a string representing the data type, and is lowercase;instanceof detects the object type (the principle is to get an object instance). Constructor detects an existing attribute type or basic data type of an object;object.prototype.toString () gets a string representing the type of the object. This method can effectively determine the array, function, regular expression, and other object types (reference types) can be judged null and undefined;
Describe how the Typeof and instanceof are conducted internally when judging the type.
Q4: What is the difference between = = and = = = in JavaScript ? Under what circumstances should they be used?
==returns if two operands are equaltrue(the operator will first cast the operand before judging and then compare equality), and if the two value types are different, they may still==, such as: one isNULLone isundefined; they==; atrueone for1, they==One is the number one is a string, the converted value is equal, then==, one value is an object, the other is a number, and the object is converted to a value of the original type (withToString() orvalueof ()), if the value is equal after conversion is also==the type is not strictly judged and is only used when comparing value sizes.
= = = Determines whether the value and type are equal (the operator is not converted before the comparison). The type is different, even if the value does not want to be equal to = = =Two numeric values are the same, unless one or two numbers are NaN(not equal at this time), they are equivalent. (NaN is not equivalent to itself, to detect the use of the global function IsNaN()), to strictly determine the type and value comparison.
A description of nan is mentioned here .
Nan:not a number, which represents a non-numeric special value that indicates that a value is not a digit, the isNaN () global function can be used to interpret whether a value is a Nan value, and Nan is not equal to all values, including itself.
Web Front End Learning-lesson two JavaScript