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 Answers
+ 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