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 jQuery Basics (2014) Creating a Simple Drawing Application Perform: Part 5

Devon Handy
Devon Handy
10,000 Points

What is the purpose of the "e" in the mousedown and mousemove functions? Is it a variable? A name?

$canvas.mousedown(function(e){
   lastEvent = e;
   mouseDown = true;

Why does it need the "e"? Where else would I need use syntax like this? How does it work? Will I ever stop asking questions? ;)

2 Answers

e is the event object. When you're dealing with event handlers, you write a function that gets called every time an event is triggered (mouse movement, mouse click, key press...).

That function gets passed an event object as a parameter. You usually call it event, evt, or just e.

The event object allows you to access the event interface, to find out what type of event it was exactly, to prevent the default behavior of the event and so on.

Jason S
Jason S
16,247 Points

I have a question about this too. What's the difference between an event and event handler and event interface , and why does mouseup not have the e? also when we write canvas.mousedown.mouseup is that the same as canvas.mousedown; canvas.mouseup?

It's a character from the show entourage i do believe.

funny but useless. please stick to comedy outside of this forum.

I only have time for one chore, Tend the garden or clean the gutters. Should I choose the farmer or the ladder?

Don't rain on my parade, bro.