Question:

Explain what the following code prints to the console.

function pirate () {
  return this;
}
console.log(pirate());

Answer:

The pirate() function returns the global window object. The global window object is created by the JavaScript interpreter when it is started to store built-in constructor functions, global constants, and global properties. When functions are invoked as functions (i.e. they are in the global namespace and are not part of an object or constructor function), the value of the this keyword is the global object.


Keywords:

© 2017 QuizBucket.org