After creating a function that returns another function, other things are in the global execution context. Things like a variable equaling another function to invoke the function factory. Then another function invokes the newly made variable equalling a returned value within the function first created.
How it works is that the global execution context runs, then executes the global variable equal to a function first. The global execution context returns a value found in the first created function. After it returns a value it’s stored in the variable memory and the execution time ends. However, the memory space for that global execution context still hangs around. Even after another line of a variable equaling a function a new execution context is created. This is what is important because each and every time a function is called a new execution context is created. Then after that second variable function is returned its value is also in memory hanging around after the function is popped off the execution stack.
Again the main take away is that every time a function is called it gets its own execution context and any functions created inside of it will point to that execution context. It is pointing to the memory space as if the other executions didn’t disappear. It knows which ones to point to properly, where and when the execution properties were created.
This is very powerful because you can have a core set of logic and make functions that are easier to use. It allows you to create new functions that have some parameters by default by using closures.<div class='sharedaddy sd-block sd-like jetpack-likes-widget-wrapper jetpack-likes-widget-unloaded' id='like-post-wrapper-155635758-346-5ce3e2a116f8b' data-src='https://widgets.wp.com/likes/#blog_id=155635758&post_id=346&origin=trilamanila.com&obj_id=155635758-346-5ce3e2a116f8b' data-name='like-post-frame-155635758-346-5ce3e2a116f8b'><h3 class="sd-title">Like this:</h3><div class='likes-widget-placeholder post-likes-widget-placeholder' style='height: 55px;'><span class='button'><span>Like</span></span> <span class="loading">Loading...</span></div><span class='sd-text-color'></span><a class='sd-link-color'></a></div>