Currently, I'm diving into an MDN article that covers async/await. I've grasped the rationale behind using the async keyword preceding functions, yet there's a bit of uncertainty regarding the await keyword. Although I've researched "await" extensively and comprehend the general idea, examples still leave me puzzled. Take this simple snippet of code (featured in the MDN article) utilizing async/await.
async function hello() {
return greeting = await Promise.resolve("Hello");
};
hello().then(value => console.log(value));
It's no surprise that this snippet logs "Hello" to the console. However, even if we remove "await," the result remains consistent.
async function hello() {
return greeting = Promise.resolve("Hello"); // without await
};
hello().then(value => console.log(value));
Could someone shed light on what exactly the await keyword followed by Promise.resolve accomplishes? Why does the output stay unchanged when it's not included? Appreciate any insights.