The garbage collector has nothing to do with it.
In JavaScript, every function returns a value. When it has no explicit return
statement, it'll implicitly return undefined
.
Of course, if you wait for an event that never happens, you'll end up waiting forever. Any callbacks registered to run when the event happens will wait with you, i.e. they'll stay in memory forever.
See for yourself:
async function foo() { /* no explicit return */ }
let result = await foo();
console.log(result); // undefined
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…