dom-events Flashcards

1
Q

Why do we log things to the console?

A

Debugging and an easy way to inspect your variables in the browser

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the purpose of events and event handling?

A

Scripts respond to events by updating the content of the web page which makes the page feel more interactive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Are all possible parameters required to use a JavaScript method or function?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What method of element objects lets you set up a function to be called when a specific type of event occurs?

A

addEventListener()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a callback function?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What object is passed into an event listener callback when the event fires?

A

An object based on event describing the vent that has returned

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between these two snippets of code?

element.addEventListener(‘click’, handleClick)

element.addEventListener(‘click’, handleClick())

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly