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

184
Visualizações
Need Clarification on Execution Context
function a(){
    b();
    var c;
}

function b(){
    var d;
}

a();
var d;

I would like a clarification on Execution Context for the code above. From what I understand, during the creation phase of Execution Context functions a and b are set as pointers to the location in heap memory and var d is set to undefined. During the execution phase, function declarations a and b are simply ignored.

What I'm confused about is when we invoke function a during execution phase, is Global Execution Context is still in execution phase later when we pop a()'s execution context from a stack, so we can process var d? Or is GEC's execution phase is over once we invoke a() and then we somehow scan the var d when GEC is the only context left on a stack?

From what I understand, after GEC execution phase, a() will be invoked and new a() execution context will be put on execution stack. Then after a()'s execution phase is done, we put new b() execution context on a stack. After we pop b()'s execution context, we can process var c and after we pop a()'s execution stack we can process var d of global execution stack.

The biggest confusion is how JS engine checks var c and var b if execution phase for both contexts is already over. Is execution phase for previous context actually over or is it still running for each context? Are we able to scan var c and var d due to a Variable Object(VO) saving information about current execution context or due to all previous execution contexts still running an execution phase? I do not understand whether execution phase for given context is finished on function invocation of a next context or when we pop a current/given context from a stack.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So, the callstack in js works on LIFO, considering your example the execution context will be executed in following manner

  1. Initial

[gec]

  1. invoking a()

[a execution context]

[gec]

  1. invoking b()

[b execution context]

[a execution context]

[gec]

  1. b() finished execution

[a execution context]

[gec]

  1. a() finished execution

[gec]

I hope this helps you!!!

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