Help in understanding javascript THIS keyword

HI, Iam not able to understand this keyword i dont know what this means inside function, inside class, inside function which is inside class, i need to understand what rules to follow while using this keyword .Kindly help

There is a lot of info on the net about it. Did you try searching for it?

If you don’t see reading about is as an option, your best bet is to write some very simple classes/regular functions/arrow functions and console.log(this) in every possible scenario. If you do that outside of all functions/classes, you’ll see that it’ll log the global browser window object, for instance.

Hi ,
i may come to know value of this doing console.log but still how could i use it at my will, though iam reading the link given above

Don’t beat yourself up if you don’t fully understand this yet in all contexts. I’ve a fairly good understanding of it, but still, whenever I use it, I first console.log it in my code to see if I really have gotten it right. It’ll take experience, it’s hard to understand just by reading theory about it.

actually i started learning react and there is so much this keyword i need to figure out this soon enough otherwise i will stuck badly . what rules u follow while using this specially in javascript classes?

Hi i asked for help regarding “this keyword” wont got enough help so i started learning from book but now there is another problem if anyone could explain this text in plain english that would be great…----

“To understand this binding, we have to understand the call-site: the
location in code where a function is called (not where it’s declared).
We must inspect the call-site to answer the question: what is this this
a reference to?
Finding the call-site is generally “go locate where a function is called
from,” but it’s not always that easy, as certain coding patterns can obscure
the true call-site.
What’s important is to think about the call-stack (the stack of functions
that have been called to get us to the current moment in execution).
The call-site we care about is in the invocation before the currently
executing function.”

thanks in advance

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.