dom-events Flashcards
Why do we log things to the console?
Debugging and an easy way to inspect your variables in the browser
What is the purpose of events and event handling?
Scripts respond to events by updating the content of the web page which makes the page feel more interactive
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?
addEventListener()
What is a callback function?
A function passed into another function as an argument, which is then invoked inside the outer function to complete some routine or action; we do not call the function ourselves
What object is passed into an event listener callback when the event fires?
An object based on event describing the vent that has returned
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
A reference to the object onto which the event was dispatched (the element that was interacted with); can use console.log or look it up on MDN
What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())
The parentheses tell the JavaScript interpreter to “run this code now”. Without the parentheses, the code won’t run until the event fires. The first is a callback function. The second we are calling the function and the value gets returned and passed in as the argument.