function in block (FiB)
a "function declaration" defined in a "block".
Last updated
Was this helpful?
a "function declaration" defined in a "block".
Last updated
Was this helpful?
⟩ ⟩ ⟩ function in block (FiB)
Don't use function (declaration) in block
a function declaration defined in a block.
sloppy mode: / initialized to undefined (outside block)
strict mode: local to the block.
JS spec says that "function declaration in block is block-scoped"
However, in most JS engines (including v8):
the identifier of the FiB is scoped outside the block
📗
function (declaration) in block
in sloppy mode:
is and visible outside the block
can be considered as a redeclaration
if there's already a function with the same name in the outer scope
the (re)assignment is not applied until the block is run
in strict mode:
is local to the block
never is a redeclaration any more
compare: var
recommendations for function in block (FiB)
don't use it
replit: