Skip to content

let variable shadowing let variable of same name cannot reference outer variable in initialiser #7939

Closed
@myitcv

Description

@myitcv

Tested with 1.8 and 1.9.0-dev.20160406

Is it intentional that the following fails to compile?

let x = 5;

{
    console.log(x); // Block-scoped variable 'x' used before its declaration
    let x = x;      // Block-scoped variable 'x' used before its declaration
    console.log(x);
}

The inner x is effectively shadowing the outer x, but only at and after the point it is redefined (i.e. the inner let x)

I couldn't find any specific mention of this in #904 which appears to be the documentation for let right now (via the spec)

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions