Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript and the DOM (Retiring) Responding to User Interaction The Event Object

Konrad Dziekonski
Konrad Dziekonski
7,798 Points

The Event Object


I dont quite understand the meaning of the event object since whene I have changed all event instaces the code were still working, as if it was just any parameter

listDiv.addEventListener('mouseover', (x) => {
    if (x.target.tagName == 'LI') {
   x.target.textContent = x.target.textContent.toUpperCase();                        

listDiv.addEventListener('mouseout', (y) => {
  if (y.target.tagName == 'LI') {
   y.target.textContent = y.target.textContent.toLowerCase();                        

vs the event keyword

listDiv.addEventListener('mouseover', (event) => {
    if (event.target.tagName == 'LI') {
   event.target.textContent = event.target.textContent.toUpperCase();                        

listDiv.addEventListener('mouseout', (event) => {
  if (event.target.tagName == 'LI') {
   event.target.textContent = event.target.textContent.toLowerCase();                        

are there any implications of not using 'event'?


2 Answers

Broderick Lemke
Broderick Lemke
13,483 Points

Hi Konrad!

The Event object is returned to you any time the event you specify is fired. The way we access it is by passing it to the callback like you do, and we assign it a name like event. event is a commonly used name because it makes sense to other developers, something we call a "Naming Convention". If I look at your code I know that event is likely an Event object because of the name. If I were to look at the first example where you call it x I wouldn't know if x was a string, number, or an Event object. Other common names given to the Event object are event, evt, and e. Because many people use these names if someone else looks at your code they'll have a better idea of what you're doing. It can also help yourself in a few months when you look at your own code. In summary: No matter the name you give the Event object, the underlying object is still given to you, but it's best practice to use a recognizable name.