Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
By using the instanceof operator,
we can determine (true or false) if an object is an instance of a
particular constructor function.
Below, we are verifying if the object InstanceOfCustomObject is an instance of the
CustomConstructor constructor function.
This works with user-defined objects as well as native objects created
with the new operator.
<!DOCTYPE html><html lang="en"><body><script> // user-defined object constructor var CustomConstructor = function() {this.foo = 'bar';}; // instantiate an instance of CustomConstructor var instanceOfCustomObject = new CustomConstructor(); console.log(instanceOfCustomObject instanceof CustomConstructor); // logs true // works the same as a native object console.log(new Array('foo') instanceof Array) // logs true </script></body></html>