Basic JS Flashcards
What is a callback function?
a callback function is a function that is passed into another function as a parameter. In this way, we have more control over when and how the callback function is run.
How does the map
function work?
The map function works by going through an array and evaluating a given callback function at each element and returning a new array with all the transformed elements
How does the filter
function work?
The filter function goes through an array and evaluates a given callback function at each element that will return true or false. Filter then returns an array with all the elements that returned truthy when passed into the callback function.
How does the console.assert
function work?
console.assert works by evaluating an expression and writing an error to the console if the expression returns falsy. Used to test the expected output of a function. If the actual output of a function is not equal to the expected output, console.assert will write an error message to the console.
What is the event object? Where is it used?
the event object is an object containing information about a given event’s properties in the HTML DOM. It can be used when programming certain actions that occur at a given event to more specifically address the events effects ( i.e. event.target gives us the HTML element the event is happening to )
What does the preventDefault function do? Where is it used?
preventDefault prevents a certain event from performing its default action. A common place it is used is in form submissions where the default action on submit is to refresh the page
What is the first argument to the sort() function? How does it work?
the first argument to sort() is a compare callback function that will compare two elements and return a number that determines which of the two elements should come first in the sort order ( -or if the number is zero, they are the same -). sort() can also take no argument and will sort the given array alphabetically.
What is the difference between setTimeout and setInterval?
both allow you to set an amount of time to wait before calling a function, but setInterval will then continue performing the function over and over again at the given interval until manually stopped