Mark As Completed Discussion

What if we had a function that is called in between the program? This would result in the creation of a local scope (for the function). A stack data structure is used here to store the local scope and it is added on the top of the stack. Remember that this local scope has its own set of variables and it ends when there is a return statement or the function is closed.

Now, what happens when the local scope of execution ends? Here, it is the responsibility of the parent scope (in our case, the global scope), to handle the return variable and continue on with its execution. The local scope of execution that was added to the stack is popped off and destroyed completely.