dom-events Flashcards
Why do we log things to the console?
debugging, confirming values or outcomes from code, communicating with other devs working on the project
What is the purpose of events and event handling?
events let us know something has occured. Event Handling allows us to take an action based on what event has occured such as running a function or changing the display of the website.
Are all possible parameters required to use a JavaScript method or function?
yes
What method of element objects lets you set up a function to be called when a specific type of event occurs?
addeventlistener
What is a callback function?
it is a method of an object that is called when a specific type of event occurs
What object is passed into an event listener callback when the event fires?
an event object
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
the event.target property refers to the element that the event occurred on. you can console log it. you can open inspector to get more info.
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())
handleClick is a reference to the function, and the function is not called until the element is clicked.
In the second case, handleClick() is actually invoked immediately, and the result of the function is passed to addEventListener as the event handler.