dom-events Flashcards
Why do we log things to the console?
We log things to the console to see if an event has fired, to make sure the listener is functioning properly, to determine that a an action has occurred during a specific event. To find the value or status of something at a period in time.
What is the purpose of events and event handling?
The purpose of events and event handling is to make webpages dynamic and allow the user to change the webpage by doing different events like clicking, hovering, pressing keys. Events occur when a page loads and some other non-user things which is also useful for event handling.
Are all possible parameters required to use a JavaScript method or function?
All possible parameters are not required to use a JavaScript method or function. Parameters can have default values. This means that when a function is called without that parameter, it will use that parameter with a default value instead of one specified during the function call.
What method of element objects lets you set up a function to be called when a specific type of event occurs?
The method of element objects that lets you set up a function to be called when a specific type of event occurs is called: addEventListeners(event, function, options or useCapture)
What is a callback function?
A callback function is a function that is passed in as an argument during a function call which is used inside the outer function to give a value.
What object is passed into an event listener callback when the event fires?
The object that is passed into an event listener callback when the event fires is the event object. The event object has properties and methods that allow the function receiving the event object to manipulate the target of the event or something else based on the event target. The event object has all the information about what was going on when the event occurred.
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 is the element that was interacted with by the user. If I was not sure I would console.log(event.target) inside the function that receives the event object. More information on the event.target could be found in MDN or other sources from google.
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())
The difference between the two snippets of code is that the first one is passing the event to the handleClick function, but not calling the handleClick function during that line of code and the second snippet passes the event to the handleClick function, but calls the handleClick function immediately, before the event occurs.