0

What does the "this" keyword do in JavaScript?

I don't understand it is it like var?

4th Sep 2018, 12:16 AM
Potato Hacker
Potato Hacker - avatar
4 Respostas
+ 5
No, it's not like var. Instead it's a reference to the object itself. Like, if you're manipulating a DOM and suppose there's a "div" you have selected and working upon then, instead of Everytime writing div.something.otherthing() you can write this.simething.otherthing() Moreover, it comes to handy when you create your own object.
4th Sep 2018, 1:01 AM
Шащи Ранжан
Шащи Ранжан - avatar
+ 4
This refers to the current object that you are using. In a HTML DOM, thia refers to the current element.
4th Sep 2018, 1:02 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
Thanks Alot Shashi Ranjan!!
4th Sep 2018, 1:02 AM
Potato Hacker
Potato Hacker - avatar
+ 2
Thanks Alot Dark Angel!!
4th Sep 2018, 1:03 AM
Potato Hacker
Potato Hacker - avatar