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

270
Visualizações
Calling one function with another function variables javascript

I am trying to learn JS internals.I am currently trying to print message "yo" both times using the two console.logs. I tried using call,bind or apply to see if it will help but it still doesn't. On the execution stack it places func2 execution context above the func1 execution context. So, I was hoping it would take the func2.

var a = 'hello';

function func1() {
    console.log(a);
}

function func2() {
    var a = 'yo';
    func1();
    console.log(a);
}

func2();
I know that if we put it as a nested function it will work.

var a = 'hello';

function func2() {
  var a = 'yo';

  function func1() {
    console.log(a);
  }
  func1();
  console.log(a);
}

func2();

Is there a way to print the internal message without declaring a function inside like the 2nd example without passing a variable to func1?

I think the reason why the first is not working is because this refers to the window but slightly confused due to Execution Context placed over the Execution Stack.

about 4 years ago · Santiago Gelvez
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