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?
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