Skip to content

Topic: Incorrect Explanation of let Hoisting in JavaScript #2

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;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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