Home > Web Front-end > JS Tutorial > How Do Block-Level Function Declarations Behave in ES6 Strict and Non-Strict Modes?

How Do Block-Level Function Declarations Behave in ES6 Strict and Non-Strict Modes?

DDD
Release: 2024-12-11 12:44:11
Original
610 people have browsed it

How Do Block-Level Function Declarations Behave in ES6 Strict and Non-Strict Modes?

Block-Level Function Semantics in ES6

Block-level function declarations were introduced in ES6, prompting questions about their semantics.

Core Semantics

Non-strict mode Strict mode
Hoisted and visible outside of the block Not visible outside of the block

Web Extension Behavior

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 Clarification

"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"; }
}
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template