Skip to content

Topic: Incorrect Explanation of let Hoisting in JavaScript #2

@Jainmanan1

Description

@Jainmanan1

Issue Description

The current explanation about hoisting for let is incorrect.

The document states that accessing a let variable before declaration returns undefined, but this is not true.

Both let and const are hoisted but remain in the Temporal Dead Zone (TDZ) until their declaration is initialized. Accessing them before declaration throws a ReferenceError.

Incorrect Example
console.log(myLetVar); // Undefined
let myLetVar = 5;

Correct Behavior
console.log(myLetVar);
// ReferenceError: Cannot access 'myLetVar' before initialization

let myLetVar = 5;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions