1

If you open chrome devtool and enter the following:

// The iife is irrelevant
let r = (() => { return 2; })();

and then evaluate r you'll see:

r
2

but window.r and globalThis.r both return undefined. I know let is block scoped but where is the r parent object? What block am I in, in the devtool that I can access r directly but it's not on any global object?

devtool-screenshot

Sam R.
  • 16,027
  • 12
  • 69
  • 122
  • At the top level of programs and functions, let, unlike var, does not create a property on the global object – bill.gates May 10 '20 at 17:49

2 Answers2

0

Apologies, I'm on my phone, so can't really verify. But I'm pretty sure there is a 'scope' tab as part of the Dev tools. If you're debugging I'm pretty sure you can see variables there in the current scope. But it's not available in the normal console

https://developers.google.com/web/tools/chrome-devtools/javascript#scope

Edit, just re-read your question, and this doesn't really answer your question description, but does kind of answer your question title. So probably going to leave the answer here for future ref

andy mccullough
  • 9,070
  • 6
  • 32
  • 55
0

The code is evaluated in global scope.Variable "let" declared Globally (outside any function) have Global Scope.

Hrithik Jaiswal
  • 74
  • 1
  • 2
  • 9