Search⌘ K

Solution Review: Instance of Array?

Explore how to use the 'instanceof' operator to check if an object is an instance of Array in JavaScript. Understand prototype chain modifications by assigning Array.prototype to a constructor's prototype to pass the 'instanceof' test. This lesson clarifies type coercion and prototype inheritance through practical coding examples.

We'll cover the following...

Solution #

Javascript (babel-node)
function check(){
var tempFunc = function () {}
tempFunc.prototype = Array.prototype
return new tempFunc instanceof Array;
}
console.log(check())

Explanation #

The exercise required you to write some code so that the line

return new tempFunc instanceof Array 
...