dom-events Flashcards
Why do we log things to the console?
for debugging, and check the data value
What is the purpose of events and event handling?
to make the web page interactive.
What do [] square brackets mean in function and method syntax documentation?
the argument is optional.
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 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?
event object, even object is always passed into the callback.
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
it’s the target property of the event object. logging the property to console, in the console.
What is the difference between these two snippets of code?
element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())
the first one is passing a function definition into a function as a callback, telling the eventListener to find that function when event fires and run it. the second one, the function is already being called and the return would be passed in as an argument. it is run as soon as the code hits it.(the page loads)