panzerdp / dmitripavlutin.com-comments

7 stars 0 forks source link

/javascript-scope-gotchas/ #66

Open panzerdp opened 4 years ago

panzerdp commented 4 years ago

Written on 04/24/2020 15:46:05

URL: https://dmitripavlutin.com/javascript-scope-gotchas/

panzerdp commented 4 years ago

Comment written by Felix Sanz on 04/29/2020 20:26:05

2. Because block scope doesn't exist pre-ES2015.

panzerdp commented 4 years ago

Comment written by Dmitri Pavlutin on 05/01/2020 07:38:00

That's right :).

panzerdp commented 4 years ago

Comment written by Hitesh Kumar on 05/12/2020 11:49:52

There's one more scope gotchas. It's around try-catch block. :)
https://smellycode.com/catc...

panzerdp commented 4 years ago

Comment written by Dmitri Pavlutin on 05/12/2020 14:44:53

Thanks for sharing @smellycode:disqus.

panzerdp commented 4 years ago

Comment written by Masha I. Klachko-Blair on 05/19/2020 21:30:46

How do you run JS in ES2015 environment? Clearly, Chrome's Console is the older environment since this code doesn't produce error:
{
function hello() {
return 'Hello!';
}
}
hello();

panzerdp commented 4 years ago

Comment written by Dmitri Pavlutin on 05/20/2020 08:04:26

I run my snippets in NodeJS v13.

basantech89 commented 2 years ago

greet function in the last question actually runs without throwing a ReferenceError, tested here https://replit.com/@basantsoni/SillyGhostwhiteScreencast#index.js

basantech89 commented 2 years ago

it should be scoped to the enclosing scope(global in this case)