JavaScript Scope
From the understanding, JavaScript Scope is divided into three scope
- Global Scope
Variables declared outside any function are in the global scope and can be accessed anywhere in the code
2. Function Scope
Variables declared within a function are only accessible inside that function.
Get Dhileep’s stories in your inbox
Join Medium for free to get updates from this writer.
3. Block scope
Variables declared with let or const inside a block are only accessible within that block.
You can get a idea from above explanation by getting it easier we can see a example of a Scope
Here I have declared globalScope variable three times you may ask that we can’t create a const name twice then now you created three times?
Based on the scopes I have declared it
you can Trace the code and compare with output so you may get a idea
OUTPUT:








