Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
If you attempt to access a property that is not contained in an
object, JavaScript will always attempt to find the property or method
using the prototype chain. Below, I create an array and then attempt to
access a property called foo that has
not yet been defined. You might think that because myArray.foo is not a property of the myArray object, JavaScript will immediately
return undefined. But JavaScript will
look in two more places (Array.prototype and then Object.prototype) for the value of foo before it returns undefined.
<!DOCTYPE html><html lang="en"><body><script> var myArray = []; console.log(myArray.foo); // logs undefined /* JS will look at Array.prototype for Array.prototype.foo, but it is not there. Then it will look for it at Object.prototype, but it is not there either, so undefined is returned! */ </script></body></html>