Front End Interview, JS Flashcards
1
Q
Define ‘this’ in JavaScript
A
When a function executes, it gets the this property—a variable with the value of the object that invokes the function where this is used.
The this reference ALWAYS refers to (and holds the value of) an object—a singular object—and it is usually used inside a function or a method, although it can be used outside a function in the global scope. Note that when we use strict mode, this holds the value of undefined in global functions and in anonymous functions that are not bound to any object.