Bug 227281 - function within a block statement has broken scope for const/let
Summary: function within a block statement has broken scope for const/let
Status: RESOLVED DUPLICATE of bug 163209
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 14
Hardware: Mac (Intel) macOS 11
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-23 01:09 PDT by Samuel
Modified: 2021-06-24 18:23 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Samuel 2021-06-23 01:09:47 PDT
When a function within a block scope tries to access a variable declared with `const`/`let` on the wrapping scope a RefferenceError is thrown.

Reproducible example:
```
{
  const a = true; // also happens with "let" declarations.
  function main() {
    console.log(a);
  }
  main();
}
```

Accessing `a` on the 4th line throws an error: "ReferenceError: Can't find variable: a".
The expected behavior would be for the "a" variable to be in the scope of the function "main".
Comment 1 Yusuke Suzuki 2021-06-24 18:23:21 PDT
This is dupe of bug 163209.

*** This bug has been marked as a duplicate of bug 163209 ***