dom-events Flashcards

1
Q

Why do we log things to the console?

A

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.

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

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.

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

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.

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

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)

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

What is a callback function?

A

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.

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

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.

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

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.

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 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.

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