JavaScript promises, mastering the asynchronous

Magus
6,249 views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Let's do some practice with a simple exercice. You must modify the code below based on the following rules:

  • The function job must return a promise object (you are in a NodeJS environment, you can use new Promise)
  • The promise must resolve itself 2 seconds after the call to job and must provide hello world in the data
Change the code to return a promise
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content
1
2
function job() {
return 'hello world';
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX