- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript instanceof
JavaScript Classes
JavaScript instanceof
instanceofchecks whether an object was built from a particular class.
typeof only ever says object, which is not much help.
instanceof answers the more useful question.
Example
Example
javascript
class Dog {}
const rex = new Dog();
console.log(rex instanceof Dog);
console.log(typeof rex);The output is true then object.
