CodeQL documentation

Access to let-bound variable in temporal dead zone

ID: js/variable-use-in-temporal-dead-zone
Kind: problem
Security severity: 
Severity: error
Precision: very-high
Tags:
   - quality
   - reliability
   - correctness
   - portability
Query suites:
   - javascript-security-and-quality.qls

Click to see the query in the CodeQL repository

The scope of a variable declared with let is its innermost enclosing block statement, loop or function. Unlike variables declared with var, variables declared with let are not hoisted to the top of their scope, giving rise to a region of code where the variable is in scope, but not declared yet. Accessing a let-bound variable inside this so-called “temporal dead zone” is permitted by some legacy implementations, but is illegal in ECMAScript 2015.

Recommendation

Move the let declaration to the beginning of its scope.

Example

In the following example, x is initialized before its declaration:

function f() {
    x = 23;
    let x;
}

The declaration should be moved as follows:

function f() {
    let x;
    x = 23;
}

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy