I noticed that the async
keyword can be assigned any value whatsoever and even used as a normal variable:
let async = "world";
console.log(async)
console.log("Hello " + async)
Yet, even then it continues to operate as before:
let async = "world";
async function foo(input) {
return input;
}
let barPromise = foo("bar");
console.log("bar promise is:", typeof barPromise);
console.log("bar promise also has a .then:", typeof barPromise.then === "function");
barPromise
.then(output => console.log("bar promise returns:", output));
console.log("async is still assigned:", async);
foo("Hello ")
.then(output => console.log(output + async));
Even await
is doing the same thing:
let await = "world";
console.log("await is:", await)
async function foo(input) {
return input;
}
async function bar(input) {
console.log("before");
let output = await foo(input);
console.log(output);
console.log("after");
}
bar("hello")
What is going on here? Why are the keywords usable as a variables?