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 trialEduardo Andre De Backer Diaz
11,472 Pointswhy event.target instead of e.target?
why event.target works?
Guil used event.target instead of e.target and still works, but why that happen if event.target isn't defined in the arrow function.
1 Answer
Steven Parker
231,198 PointsIt's a default functionality of most browsers.
It's common for the browser to create a global variable named "event" and give it the current event object when the name is not already being used for something else. But this is not guaranteed, and using it is not recommended. I suspect it was an error in the video that was not caught because it worked anyway.
The "best practice" approach is to make use of the passed-in argument ("e" in this case) when referencing the event object.