JS: Difference Between typeof, instanceof, constructor property
typeof
return the type of the object, but array, object, date, regex, etc all just return"object"
. [see βtypeofβ Operator]instanceof
checks if a object is in the Prototype Chain of a function's property"prototype"
's value. [see instanceof Operator]- Property key
"constructor"
is meant to return the function that created the object.
π‘ TIP: You shoud avoid using any of them, because they are not reliable.
Instead, check directly what you are looking for, by:
- Check for parent object. [see Get Set Prototype]
- Check for the exact βsubtypeβ of a object. [see Determine Type of Object]
- Check for the exact property, own or inherited. [see Check Property Existence]
JavaScript, Constructor, Class
- JS: this Binding
- JS: What is Constructor
- JS: Property Key "prototype"
- JS: Operator βnewβ
- JS: instanceof Operator
- JS: Property Key "constructor"
- JS: Difference Between typeof, instanceof, constructor property
- JS: Class
- JS: Class Syntax
- JS: Class Expression
- JS: typeof Class
- JS: Keyword βstaticβ (static method)
- JS: Keyword βextendsβ
- JS: Keyword βsuperβ
- JS: Define a Class Without Using Keyword class