JavaScript Flashcards

1
Q

Why do we log things to the console?

A

To test if the code is working

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

What is a “model”?

A

contains the interactive data

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

Which “document” is being referred to in the phrase Document Object Model?

A

html

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

What is a DOM Tree?

A

as a browser loads a web page it creates a model of that page and it consists of four types of nodes the document node element node attribute and text nodes.

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

Give two examples of document methods that retrieve a single element from the DOM.

A

getElementById and querySelector:

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

Give one example of a document method that retrieves multiple elements from the DOM at once.

A

querySelectorAll

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

Why might you want to assign the return value of a DOM query to a variable?

A

In order to console log

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

What console method allows you to inspect the properties of a DOM element object?

A

console dir

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

Why would a tag need to be placed at the bottom of the HTML content instead of at the top?

A

it gives the html body time to load before any of the javascript loads

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

What does document.querySelector() take as its argument and what does it return?

A

returns the first element

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

What does document.querySelectorAll() take as its argument and what does it return?

A

returns a static node list

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

What is the word “object” referring to in the phrase Document Object Model?

A

the nodes of a dom tree

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

Why do we log things to the console?

A

to inform developers what the code is doing

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

What is the purpose of events and event handling?

A

in order to make web content more dynamic and interactable

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

What do [] square brackets mean in function and method syntax documentation?

A

Square brackets are used to index (access) elements in arrays and also Strings. Specifically lost[i] will evaluate to the ith item in the array named lost.

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

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

A

addEventListener

17
Q

What is a callback function?

A

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.

18
Q

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

A

The event object.

19
Q

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

A

Whatever html element was targeted you could console log.

20
Q

What is the difference between these two snippets of code?

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

A

element. addEventListener(‘click’, handleClick()) it is executing the function
element. addEventListener(‘click’, handleClick) is just referencing the function