`function` Declarations Are Function Scoped, But `async Function` Declarations Are Block Scoped?
Should the following code work? if(true) { async function bar() { console.log('hello'); } } bar(); Chrome 80 and Firefox 72 both throw a ReferenceError saying bar is not d
Solution 1:
It seems like
async function bar() {...}
declarations are block scoped
Yes, just like normal. Function declarations are block-scoped in general.
… whereas
function bar() {...}
declarations are function scoped?
Not really, except in sloppy mode for legacy reasons. This does not affect async function
and function*
declarations, which don't need any backwards-compatibility.
Post a Comment for "`function` Declarations Are Function Scoped, But `async Function` Declarations Are Block Scoped?"