JavaScript Flashcards
(235 cards)
Why do we log things to the console?
to see the state of the code
tracking values, debugging
What is a “model”?
a recreation of something for resemblance
Which “document” is being referred to in the phrase Document Object Model?
HTML document
What is the word “object” referring to in the phrase Document Object Model?
javascript object
What is a DOM Tree?
element and all of its content
Give two examples of document methods that retrieve a single element from the DOM.
queryselector and getelementbyid
Give one example of a document method that retrieves multiple elements from the DOM at once.
queryselectorall
Why might you want to assign the return value of a DOM query to a variable?
to be able to reuse it later
so you don’t have to do the same work
Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?
so the html and css finishes loading
What console method allows you to inspect the properties of a DOM element object?
console.dir
What does document.querySelector() take as its argument and what does it return?
css selector and it returns first element of that selector
What does document.querySelectorAll() take as its argument and what does it return?
css selector and a nodelist with all elements with that selector
Why do we log things to the console?
to verify values and debug
What is the purpose of events and event handling?
events are for detecting user interaction and response
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?
function that gets called when something else happens
What object is passed into an event listener callback when the event fires?
callback function
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
event target is to see which event triggered. if you didn’t know, you could look it up on mdn
What is the className property of element objects?
get or set value of class attribute on html element
How do you update the CSS class attribute of an element using JavaScript?
classname property of object equal operator to value
What is the textContent property of element objects?
text that is being displayed
Is the event parameter of an event listener callback always useful?
no
Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?
more complicated