What is ‘this’ in Javascript world?

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)

Author: Ankur

I am Enthusiastic about Learning new things and sharing my Knowledge. I like programming and have a pretty good background in Computer Science.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s