typeof is used to detect the data type of a given variable (also called the basic type, the base data type.) Contains Undefined, Boolean, string, number, object, function
var message = ' So easy ';
Alert (typeof message); "String"
Alert (typeof 12); "Number"
Memory: typeof is used to judge "variables" that are not created with new.
Instanceof is used to detect the type of an object (also referred to as a reference type.) Contains object, Array, Date, RegExp, Function, base wrapper type (including Boolean, number, String)
var numberobject = new number (10);
var numbervalue = 10;
Alert (typeof Numberobject); "Object"
Alert (typeof Numbervalue); "Number"
Alert (numberobject instanceof number); True
Alert (numbervalue instanceof number); False
Numbervalue is the number underlying data type and does not belong to any reference type.
Numberobject is the object underlying data type, which belongs to the number reference type (all reference types inherit from the object reference type).
You can remember this: instanceof detects "objects" created with new. "Variables" that are not created by new are not part of any reference type. Using typeof to detect "objects" created with new always returns an object reference type.
The isPrototypeOf () method is used to detect the relationship between the prototype and the instance. Instanceof can also be detected. As long as the prototype in the prototype chain, can be said to be the prototype chain derived from the prototype of the instance.
var person = new person (); Person inheritance and Object
Alert (Person.prototype.isPrototypeOf (person)); True
Alert (Object.prototype.isPrototypeOf (person)); True