Skip to content

Instantly share code, notes, and snippets.

@khalidwilliams
Last active October 19, 2020 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save khalidwilliams/df7f02997b56a0395902a1ae54a830ec to your computer and use it in GitHub Desktop.
Save khalidwilliams/df7f02997b56a0395902a1ae54a830ec to your computer and use it in GitHub Desktop.

Don't forget to call for help if you need it in your breakout rooms!

Warm Up

Hint: Don't be afraid to look at documentation for any of these questions!

@kabeer11000
Copy link

if i add async key word to a function say

async function addNumbers (num1, num2) {
	return num1 + num 2
}

it will return a Promise with Resolve and Reject which can be handled by .catch, .then, .finally
await keyword is used to block execution of code inside an async function say

async function addAndMultiply ( num1, num2, multi ) {
	return await addNumbers(num1, num2) * multi
}```

and for your function it will look kinda like this
```javascript
const getAdvice = async () => await fetch('https://api.adviceslip.com/advice')
		.then(response  => response.json())
		.catch(error => console.error(error));

getAdvice()
	.then(advice => {
		const advice =  advice
}).catch(error => console.log(error));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment