JavaScript Flashcards
(129 cards)
What is the purpose of a loop?
repeat code until a condition criteria is met
What is the purpose of a condition expression in a loop?
determine an end state of the loop
What does iteration mean in the context of a loop?
pass through the loop code
When does the condition expression of a while loop get evaluated?
before each iteration
When does the initialization expression of a for loop get evaluated
beginning, only run once
When does the condition expression of a for loop get evaluated?
before every iteration
When does the final expression of a for loop get evaluated?
after the loop code block
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
What does the ++ increment operator do?
adds 1 to the variable
How do you iterate through the keys of an object?
for in loop
Why do we log things to the console?
To check for bugs, double check our work.
What is a “model”?
A copy or representation of the original
Give two examples of document methods that retrieve a single element from the DOM.
getElementById()
querySelector()
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?
So the browser does not need to search for it every time it needs it
What console method allows you to inspect the properties of a DOM element object?
console.dir()
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
The browser needs to load all the HTML before JS can be run on it.
What does document.querySelector() take as its argument and what does it return?
an element, id, or class returns the first element it finds with matching element, id, or class
What does document.querySelectorAll() take as its argument and what does it return?
takes element, id, or class
returns all elements with that tag, id, or class
Which document is being referred to in the phrase DOM
HTML
What is the word object referring to in DOM
refers to JS objects
What is a DOM tree
model of the html document represented as a JS object (DOM generally), tree is series of objects elaborating on a chunk of the html document.
What is the purpose of events and event handling?
add dynamic content, user interactivity, respond to an occurrence
Are all possible parameters required to use a JavaScript method or function?
No