Transcript from the "Call Stack" Lesson
[00:00:49] We're not gonna go deeply into their premise, but a key thing with a stack is when you add something to it, when you run a function we're going to add it to our call stack. So when we started running multiply by two up here, we add it to our call stack, multiply by two with the input of three.
[00:01:26] So whatever's at the top of the call stack, that's where we are right now. As soon as we finish running that function, and by the way, Adam, actually, [SOUND] Jeff? Jeff, what, Jeff tells us, we have finished executing a function, what keywords says, end this function, move on.
>> Speaker 2: Return.
>> Will Sentance: Return exactly, as soon as we hit return this function execution context popped off the call stack, so what's top? That was underwhelming, so what is top of the call stack now? Well is there anything? Yeah, always on the bottom of the call stack folk is our global execution context.
[00:02:31] Well don't panic, what's left on the call stat, Kayla?
>> Speaker 3: Global.
[00:02:50] It goes back to global, if I were to run another function inside of multiplyBy2, that would be added on top, another inside of that, that would be added on top. Finish running that one, do I go back to global? I go back to wherever I started running that function, in other words, take it off the stack and about where I was before and that's the key premise of a stack.
[00:03:39] And in a sort data, we saw code to run, think about it, you're literally able to start a little mini program of your choice at any moment in your code. And, then we have the thread of execution to go through the code line by line, a lot of the time it's storing data, but it's also taking some of the stored functionality code and saying start running it.
[00:03:57] We create a little mini program, a little sub-program, a execution context into which we go and compartmentalize any data we're storing while we're inside that function. When we exit that function, all is deleted, besides whatever we return out, let's actually show that all is deleted, the size, whatever we return out, and then run another function do the same.
[00:04:23] We keep track of the functions we're running and where our thread of execution is using our call stack.