content(resources): update/tweak JS promises resources

This commit is contained in:
Jean-Philippe Sirois
2020-05-20 23:27:22 -04:00
parent a472a6a1da
commit 7a369f9d34
2 changed files with 61 additions and 24 deletions
@@ -1,8 +1,9 @@
---
authors:
- "Xetera#0001"
- "veksen#1060"
created_at: 2019/07/26
updated_at: 2019/07/26
updated_at: 2020/05/20
title: Introduction to Promises
recommended_reading:
- javascript/callbacks/intro
@@ -85,6 +86,14 @@ getWeather("Los Angeles").then((weather) => {
});
```
Outlining this one again, because it's very common, is to attempt to use the value of a promise, but not resolving it:
```js
// Incorrect code, don't copy!
const weather = getWeather("Los Angeles");
console.log(weather); // Promise {<pending>}
```
## Real World Example
Here is a real function that gets character information from the Rick and Morty API.