Although the two operators are similar, in fact, the difference is very large, although it is not difficult to distinguish, but for beginners may have a little trouble, the following is a brief description of the difference between them, I hope to need a friend to help
One. instanceof operator: This operator can determine whether a variable is an instance of an object (class), and the return value is a Boolean type. To understand its role, you must have an understanding of object-oriented: code examples are as follows: The code is as follows: Var str=new String ("Antzone"); Console.log (str instanceof String); The above code outputs True because STR is an object instance of object string. In general, only objects created with constructors return true, or False if the array is an exception, and returns True. Two. typeof operator: This operator can return a string that describes the type of the element arithmetic, and its return value is as follows: The copy code code is: number,boolean,string,function,object,undefined First look at a generation Code instance: codes are 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 exact type "string", and the second is "object", which is not accurate. In general, the use of typeof is a direct amount of form can return accurate results, if the use of constructors created objects will return "object", but for the array is an exception, regardless of whether the direct amount will return "object."