
Block 1 shows a huge open box is show that is labeled as GLOBAL. Block 2 shows 3 boxes placed one above the other, where the size of the boxes decrease as it goes upward. The boxes are labeled FUNCTION. Block 2 is placed above block 1 at the top right. Block 3 shows 2 boxes placed one above the other, where the size of the box at the top is smaller than the box at the bottom. The boxes are labeled FUNCTION. Block 3 is placed above block 1 at the bottom right.
Note: Each function is like a box with a one-way window. Six points related to the scope in JavaScript is written according to the figure as follows.
Point 1: Within any function, it can see out at the content of all its outer boxes.
Point 2: But an outer function can’t look into an inner function.
Point 3: And functions can’t see into other functions at the same level.
Point 4: All functions can see anything within global scope.
Point 5: Scope ends at global; functions can’t see outside of the global box.
Back