Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda