Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!