JS: typeof, instanceof, .constructor
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: Constructor and Class
- JS: this (binding)
- JS: Constructor
- JS: prototype (property)
- JS: new (operator)
- JS: instanceof (operator)
- JS: constructor (property)
- JS: typeof, instanceof, .constructor
- JS: class (keyword)
- JS: Class Expression
- JS: typeof Class
- JS: static (keyword)
- JS: extends (keyword)
- JS: super (keyword)
- JS: Define a Class Without class