04:49 | <Tushar Vaswani> | Hey guys I was reading about environment records and lexical environment and I got a confusion. Don't know if this is the right channel to discuss about this. But basically my question is this: If we have this code:
Then here x was part of lexical environment(and ultimately environment record) of the block. That's why it will not be accessible outside the block. But var is accessible becasue it's not block scoped. So does that mean it's not stored in environment record of block and stored directly in global environment record (and global object basically?) or in both global environment record and environment record of block. |
04:51 | <rkirsling> | yeah, var effectively "doesn't see" {} |
04:53 | <Tushar Vaswani> | yeah, |
04:54 | <Tushar Vaswani> | I was mainly confused because its not clearly outlined in spec |
04:55 | <rkirsling> | yeah, "lexical" refers to the {} , let , const mechanism |
04:55 | <rkirsling> | var just knows about function scopes and global scope |
04:55 | <Jessidhia> | that depends on strict mode and on whether it’s inside or outside a function body |
04:56 | <Jessidhia> | it won’t be global on a strict mode script… IIRC |
04:58 | <Tushar Vaswani> | |
05:01 | <Tushar Vaswani> | it won’t be global on a strict mode script… IIRC |
05:02 | <Tushar Vaswani> | Well actually maybe I misunderstood it because I just tried it and it seems to work still:
|
05:03 | <rkirsling> | you'd want to check globalThis.a but I do think it works, yeah |
05:04 | <Tushar Vaswani> | you'd want to check |