Home >Web Front-end >JS Tutorial >How Do Block-Level Function Declarations Behave in ES6 Strict and Non-Strict Modes?
Block-level function declarations were introduced in ES6, prompting questions about their semantics.
Non-strict mode | Strict mode |
---|---|
Hoisted and visible outside of the block | Not visible outside of the block |
In browsers, web extension semantics apply to block-level functions in non-strict mode:
Web Extensions | Hoisted? | Visible Outside of Block? | TDZ? |
---|---|---|---|
Yes | To both the block and function | Yes, as a var declaration | Undefined prior to block execution |
"Strict mode" in the context of block-level functions refers to the strictness of the function in which the block containing the function declaration occurs. The following example demonstrates this:
// Non-strict surrounding code { function foo() { "use strict"; } }
This code is considered "strict mode" for function foo.
The above is the detailed content of How Do Block-Level Function Declarations Behave in ES6 Strict and Non-Strict Modes?. For more information, please follow other related articles on the PHP Chinese website!