Accessing the value from a Promise using await in JavaScript (day-18/18_Day_Promises.md)
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 82/100
- Issue type
- Documentation
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- javascript
- Domain
- documentation
Research direction
Open day-18/18_Day_Promises.md and review the section explaining await with the example in the issue. Update the lesson so it explains the top-level error and shows the async main() approach, then verify the example displays the expected value 4.
Written by the indexing model from the issue text.
Description
We want to access the value returned from an asynchronous function using await, but it causes an error when used at the top level.
const square = async function (n) {
return n * n;
}
const value = await square(2); // ❌await is only valid in async functions and the top level bodies of modules
console.log(value);
CORRECT APPROACH:
const square = async function (n) {
return n * n;
}
async function main() {
const value = await square(2);
console.log(value); // 4
}
main();
- Dominant language
- JavaScript
- Stars
- 46.8k
- Forks
- 10.5k
- Avg merge
- 1m
- Merged PRs (30d)
- 1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Asabeneh/30-Days-Of-JavaScript
-
Day 14 Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Asabeneh/30-Days-Of-JavaScript#1020 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 62/100
Asabeneh/30-Days-Of-JavaScript#908 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
-
day 23, typos Open
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
All issues in Asabeneh/30-Days-Of-JavaScript
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·
-
client-controller-update ta-bot-triage team-money-movement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MetaMask/metamask-mobile#36594 ·