Skip to content

'let' loses its block scope when using same argument name in self-invoking function inside for-loop #763

Closed
@dashukin

Description

Invalid behavior:

for (let i = 1; i < 3; i += 1) {
  (function (i) {
    console.log(i);
  }(i))
}
console.log(i);
 // 1,2,3

Valid behavior:

for (let i = 1; i < 3; i += 1) {
  (function (a) {
    console.log(a);
  }(i))
}
console.log(i); 
 // 1, 2, i is not defined

Metadata

Assignees

No one assigned

    Labels

    outdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions