...

/

Solution Review: Asynchronous Callback Functions

Solution Review: Asynchronous Callback Functions

This lesson will explain the solution to the problem in the previous lesson.

Solution #

Press + to interact
const getTodo = callback => {
setTimeout(() => {
callback ({ text: 'Complete Code Example' })
}, 2000)
}
function display(){
getTodo(todo => {
console.log(todo.text)
})
}
display()

Explanation #

Before we discuss the solution above, let’s discuss what the original code was doing.

Press + to interact
const getTodo = () => {
setTimeout(() => {
return { text: 'Complete Code Example' }
}, 2000)
}
function display(){
const todo = getTodo()
console.log(todo.text)
}
display()

The getTodo function has the setTimeout function which returns ...

Access this course and 1400+ top-rated courses and projects.