Question:

What does the following code print to the console?

function sampleFun() {
  console.log(this);
}

Answer:

The global window object

The this keyword has different values depending on when it is used. When the this keyword is used in a function that is invoked in a function context (meaning the function is not part of a constructor function or the property of an object), then the this keyword refers to the window object. The this keyword is rarely used for functions that are invoked in a function context.


Keywords:

© 2017 QuizBucket.org