Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Why "self" is needed instead of "this" in JavaScript?

I was asked this question recently and I had no answer to it , since I have never came across "self" as far as I remember. Can someone please explain me the concept behind this?

Is this something that was/is of great importance in JavaScript ?

Steven Parker
Steven Parker
243,658 Points

Which course/video are you referring to? Can you provide a link to it?

Hi Steven,

This is an open end question regardless of any tutorial in Treehouse(even I haven't came across something like this in Treehouse yet). I am curious to know.

1 Answer

Steven Parker
Steven Parker
243,658 Points

:point_right: You'll generally see "this" used consistently in JavaScript.

I don't think you're likely to see "self" used in the same way. I would be curious to know what the person asking the question was referring to.

Could they possibly be confusing JavaScript with Python?

I am pretty sure the person was completely talking in a Javascript reference.

The below link is from the Mozilla dev network, and that's maximum explaination I could find on this topic : https://developer.mozilla.org/en/docs/Web/API/Window/self