JavaScript Flashcards
What is the purpose of a loop?
To execute a block of code as long as specified condition is true
What is the purpose of a condition expression in a loop?
The purpose of condition expression in a loop is to be tested each time loop runs. As long as condition is true loop keeps running
What does “iteration” mean in the context of loops?
repetition of a process
When does the initialization expression of a for loop get evaluated?
only first time before loop starts
When does the condition expression of a for loop get evaluated?
before each loop iteration
When does the final expression of a for loop get evaluated?
At the end of each loop iteration
What is the word “object” refers to in the phrase Document Object Model?
The word “object” refers to the structured representation of an HTML or XML document.
What is a DOM Tree?
A collection of objects in the computer memory that represent the HTML elements that define a web page.
Give one example of a document method that retrieves multiple elements from the DOM at once.
document.querySelectorAll()
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?
document.querySelector() takes a CSS selector string as its argument. And returns the first element that matches specified CSS selector.
What does document.querySelectorAll() take as its argument and what does it return?
It takes CSS string selectors as argument and returns static NodeList representing a list of documents that match argument
What is the purpose of events and event handling?
It’s to interact with users in a specific way depends on user actions
What method of element objects lets you set up a function to be called when a specific type of event occurs?
addEventListener
What object is passed into an event listener callback when the event fires?
function object
How do you update the CSS class attribute of an element using JavaScript?
by calling className property
Why is it possible to listen for events on one element that actually happen its descendent elements?
due to the event bubbling
What DOM element property tells you what type of element it is?
tagName
What does the element.closest() method take as its argument and what does it return?
As argument it takes string as CSS selector, it’s heading towards document root until it finds a node that matches provided selector string
How can you remove an element from the DOM?
By using remove() method -> element.remove()
If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?
add eventListener to the parent element and verify from which element event come from (condition)
Is the event parameter of an event listener callback always useful?
yes
What event is fired when a user places their cursor in a form control?
focus
What event is fired when a user’s cursor leaves a form control?
blur
What does the event.preventDefault() method do?
preventing refresh the page
What does submitting a form without event.preventDefault() do?
It refreshes webpage
What property of a form element object contains all of the form’s controls.
The HTMLFormElement.elements returns an HTMLFormControlsCollection
What is the textContent property of an element object for?
textContent property let us add text value to an element object or check text value of an element object
Name two ways to set the class attribute of a DOM element.
className and setAttribute