Solution Review: Promises
In this lesson, we will discuss the solutions to the questions in the previous lesson.
We'll cover the following...
Press + to interact
function func1(){return new Promise(function(resolve,reject){setTimeout(function(){resolve("Func1")},1000)})}function func2(){return new Promise(function(resolve,reject){setTimeout(function(){resolve("Func2")},2000)})}func1().then(func2()).then(function(result) {console.log(result);});
For the code above, you had to answer the following question:
Explanation #
Run the code below to see the solution.
Press + to interact
function func1(){return new Promise(function(resolve,reject){setTimeout(function(){resolve("Func1")},1000)})}function func2(){return new Promise(function(resolve,reject){setTimeout(function(){resolve("Func2")},2000)})}func1().then(func2()).then(function(result) {console.log(result);});
As you can see, the correct option is C. Let’s discuss the code to understand the answer.
On line 18, the func1
function executes, and according to its definition on lines 1-7, it returns a promise. ...