Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda