In this short video tutorial I explain the basics of this keyword in Javascript. It’s a confusing concept for those starting out with Javascript.
-- QUICK INTRODUCTION TO this KEYWORD
-- If a function has a this reference in it, it points to an object. The object it points to depends on how the function was invoked.
-- It does not refer to the function itself.
function simpleFn() {
console.log(this) // this points to an object
}
simpleFn() // -- window
let myObject = {
myFunctionTwo: simpleFn,
name: 'Ankur',
age: 36
}
myObject.myFunctionTwo()
// strict KEYWORD
// .call(obj2)