Call Stack Flashcards

1
Q

What is the Call Stack?

A

The call stack is the JS compilers todo list. The elements in the stack are pulled in until there is nothing left, at which point the last element will be executed and popped off the stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When is a stack overflow error triggered?

A

When there are 16000 entries in the stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can you track code moving through the call stack?

A

With Chrome DevTools. Open the file you want to track in sources and add a breakpoint. You can see the call stack in the right hand panel.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In what order is the following code added to the stack and executed?

function greeting() {
  sayHi();
}
function sayHi() {
  return "Hi!";
}
greeting();
console.log('all done')
A

The compiler will skip over the initial functions and look for the first executable call, greeting(). This is added to the stack, followed by sayHi(). at this point the stack looks like below. The top of the stack returns “Hi”, and is popped off, followed, by greeting().

say(hi)
greeting()
main()

Then console.log is added and executed before the stack is cleared.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly