Dom-events-Q&A Flashcards
Why do we log things to the console?
So we know what is going on in our javascript
What is the purpose of events and event handling?
An event handler is a routine that deals with the event, allowing a programmer to write code that is executed when the event occurs.
Are all possible parameters required to use a JavaScript method or function?
No!
What method of element objects lets you set up a function to be called when a specific type of event occurs?
The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target. Common targets are Element , or its children, Document , and Window , but the target may be any object that supports events.
What is a callback function?
A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.
What object is passed into an event listener callback when the event fires?
The function that we assign as a callback to an event listener is passed the event object as its first argument. We can use this object to access a wealth of information about the event that has occurred: type (string) This is the name of the event. target (node) This is the DOM node where the event originated.
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
The read-only target property of the Event interface is a reference to the object onto which the event was dispatched. It is different from Event.currentTarget when the event handler is called during the bubbling or capturing phase of the event. (MDN)
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
the parentheses are omitted where the function is called because they would indicate that the function should run as the page loads (rather than when the event fires).