JavaScript Flashcards
- What is a function in JavaScript?
a set of statements that performs a task or calculates a value
- Describe the parts of a functiondefinition.
Function keyword
the first line (including the argument declarations), and the so-called body of the function
- Describe the parts of a functioncall.
the name of the function being executed followed by a list of values, called arguments, which are assigned to the parameters in the function definition
- When comparing them side-by-side, what are the differences between a functioncalland a functiondefinition?
The definition has a code block while the call doesn’t
Parameter are a new thing while the call is just inserting something
Function keyword
- What is the difference between aparameterand anargument?
Parameter are place holder names for when something is defined
Arguments are used when it is called .
- How do you compare two different expressions in the same condition?
Using one of the logical operators &&, ||
What is the event.target?
It is a reference to the object onto which the event was dispatched
Its the element that the event originated
Why is it possible to listen for events on one element that actually happen its descendent elements?
Bubbling
What DOM element property tells you what type of element it is?
Element tag name; property comes back upperCased
What does the element.closest() method take as its argument and what does it return?
It takes a valid css selector to match the element and it returns the closest ancestor element or itself; closest searches outwards while query is inward.
How can you remove an element from the DOM?
Using the 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 an event listener to its ancestor; event delegation
What is the affect of setting an element to display: none?
It hides its content, does not take any space, outside of the flow.
What does the element.matches() method take as an argument and what does it return?
It takes a valid css selector and returns true if the element matches the selectors otherwise false
How can you retrieve the value of an element’s attribute?
getAttribute; the value of the attribute we’re trying to get
At what steps of the solution would it be helpful to log things to the console?
After every line of code
If you were to add another tab and view to your HTML, but you didn’t use event delegation, how would your JavaScript code be written instead?
You would need a separate function for each view