Basic JS Flashcards

1
Q

What is a callback function?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does the map function work?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does the filter function work?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does the console.assert function work?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the event object? Where is it used?

A

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 )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the preventDefault function do? Where is it used?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the first argument to the sort() function? How does it work?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between setTimeout and setInterval?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly