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

197
Visualizações
When is the closure removed in Javascript?

I am curious how the closure in Javascript removed.

I know the definition of closure. It is a variable which is referred by child function inside of a parent function that lifecycle is over.

Here is the example below:

    let inner;

    function outerFunction() {
      let outerValue = 'Mike'

      function innerFunction() {
        let message = `${outerValue} is a developer`

        console.log(message) // Mike is a developer
      }

      inner = innerFunction;

      return
    }

    outerFunction()
    inner()

As you can see, when outerFunction is called, eventually it is removed from callstack due to return statement.

After outerFunction, inside which is the variable assigned innerFunction is called.

innerFunction shows the message 'Mike is a developer'. However it does not return.

In this case, when does innerFunction is removed from callstack?

The function does not return and hold a variable from outerFunction. If this remains in memory then it must be a huge waste.

Or is innerFunction also removed when outerFunction returns?

about 4 years ago · Juan Pablo Isaza
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