1.instanceof operator:
This operator can determine whether a variable is an instance of a certain object (class), and the return value is Boolean type.
If you want to understand its role, you must understand the target:
Code examples are as follows:
Copy code code as follows:
var Str = New String ("Antzone");
console.log (Str Instanceof String);
The above code will output True, because STR is an object instance of the object String.
Generally speaking, only the object created by the constructor will return True, otherwise it will return false, but the array is an exception and will return True.
2.Typeof operator:
This operator can return a string, which explains the type of meta calculation. Its return value is as follows:
Copy code code as follows:
Number, Boolean, String, Function, Object, Undefined
First look at a code example:
Copy code code as follows:
var Str = New String ("Antzone");
var Strtwo = "Antzone";
console.log (Typeof Str);
console.log (Typeof StrTwo);
In the above code, the first one can output the accurate type "String", and the second is "Object", which is not accurate.
Generally speaking, the use of Typeof's operation is a direct quantity form to return the accurate result. If it is an object created by a constructor, it will return "Object", but it is an exception for the array. "