Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
How Call Stack of JS knows where to continue?

I wanna know how callstack works after one pops.

For example:

function inner() {
  console.log("what happens after inner() pops at Call Stack?");
}

function outer() {
  inner();
  console.log("how can Call Stack returned to this line?");
}

outer();

I can tell that on Call Stack:

  • at first we have outer() pushed,
TOP of Call Stack
----------------
outer() // not executed. so lets begin at line 1!
----------------
BOTTOM of Call Stack
  • and now we meet inner() at the first line of outer() and pushed it to Call Stack,

so we have

TOP of Call Stack
----------------
inner() // not executed yet!
outer() // line 1 is on… 
----------------
BOTTOM of Call Stack
  • and when console.log of inner() executed, inner() ends,
  • and Call Stack pops inner(),

so we have

TOP of Call Stack
----------------
outer() // line 1 is executed. let's continue with line 2! 
----------------
BOTTOM of Call Stack

But HOW DOES CALL STACK KNOWS WHERE TO CONTINUE when they get back to outer()? how can outer() at the top of stack does not re-start at the first line? do they memories some things like pointer(that points the line of outer function)? but at where? what if recursive function happens like 100 times, so when we have 100 stacks, where they memories all the positions where to continue?

thanks for your help.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The call stack doesn't just store the function to return to, but also the particular location within that function.

It also stores the values of local variables inside the function. This is essential to make recursive functions work properly.

Note that all this is an implementation detail of the JavaScript VM, and it could be implemented in various ways. For example, the return location could be a memory address after JIT-compiling the JavaScript to machine code. Or the function could be inlined, leaving no stack frame at all.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!