Javascript Timers Flashcards

1
Q

What is a “callback” function?

A

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

function greeting(name) {
  alert('Hello ' + name);
}
function processUserInput(callback) {
  var name = prompt('Please enter your name.');
  callback(name);
}

processUserInput(greeting);

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

Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?

A

setTimeout

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

How can you set up a function to be called repeatedly without using a loop?

A

setInterval

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

What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?

A

0

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

What do setTimeout() and setInterval() return?

A

intervalID is a numeric, non-zero value which identifies the timer created by the call to setInterval(); this value can be passed to clearInterval() to cancel the interval.

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