Advertisement
karlakmkj

async...await function

Dec 30th, 2020
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const brainstormDinner = require('./library.js')
  2.  
  3. // Native promise version:
  4. function nativePromiseDinner() {
  5.   brainstormDinner().then((meal) => {
  6.       console.log(`I'm going to make ${meal} for dinner.`);
  7.  })
  8. }
  9.  
  10. nativePromiseDinner();
  11.  
  12. // async/await version: (Will produce the exact same result as the native promise)
  13. async function announceDinner() {
  14.  // Write your code below:
  15.  let meal = await brainstormDinner();  //create a variable to hold the resolved value of the promise returned from brainstormDinner()
  16.  console.log(`I'm going to make ${meal} for dinner.`); //Then we can write our console.log()
  17.  
  18. }
  19.  
  20. announceDinner();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement