iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🤝
Is JavaScript async/await Syntactic Sugar for Promises?
Q. Is JavaScript's async/await syntactic sugar for Promise?
A. It is not syntactic sugar.
Q. Why?
A. When you call the Function.prototype.toString method on a function object created with the async function syntax, you get a string starting with async function. This is impossible with Promise alone and cannot be achieved without using the async function syntax.
async function foo() {}
// "async function foo() {}"
console.log(Function.prototype.toString.call(foo));
*Note: Here, syntactic sugar is defined as "a syntax that allows a program using it to be consistently rewritten into an equivalent program that does not use that syntax."
Q. So what?
A. Well...
Discussion