DEV Community

Discussion on: Block scope in javascript

Collapse
 
badgamerbad profile image
Vipul Dessai

The example code and the output that you have given seems to be of two different examples, the output if no functions are involved, should be

9
10
0
Outside:
100
98
0
Enter fullscreen mode Exit fullscreen mode

Also if you add an example of a function and show how the value of var does not change, that might help too.

Collapse
 
aishanipach profile image
Aishanii

Attached the wrong screenshot, I was playing around with the function example as well, which I mentioned too. Mistake on my end. Thank you for correcting!

Collapse
 
badgamerbad profile image
Vipul Dessai

No problem, happy to help, also i forgot to mention, in the quote at the end, the variable names have to the same in that example to give a syntax error, however it wouldn't be shadowing effect anymore, as they become part of the same scope.

Thread Thread
 
aishanipach profile image
Aishanii

Thank you so much for your help and correcting me. So much to learn!