typeof operator: This is used to identify the type of variable. It returns a variable type. It is the easiest way to check the type of the variable. It works for some variables, but it did not identify the exact type of variable.
Conditions: It treated array, set, and null same as the object. typeof returns object for all of these. In the case of variable except three of this typeof is used.
object object object string object undefined
instanceof operator: This is used to check if any instance is made with a certain constructor or not. It returns true if it is made with constructor else returns false. It only works for those who are wrapped in regular object types.
Condition: It treats the array and sets the same as the object. So we can use instanceof operator for all values except these two.
Variable instaceof object;
True True True false false false
constructor property: This is the property of the variable which points to the fundamental object constructor type of that object. We can check for those variables which have constructor property.
Condition: The constructor method throw an error for variables not having constructor property. null and undefined don’t have constructor property, so it throws an error.
Variable.constructor === Object
True false false false