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

390
Views
Why my insisde function cannot find variable the higher function (Javascript)?

I'm trying to understand scope in Javscript, and have some problem. Code:

const callback = (arg) => {
  console.log(arg);
};

function mainFunc(z) {
  const cb = z;
  insideFunc();
}

function insideFunc() {
  cb('1');
}


mainFunc(callback);

Why insideFunc cannot find cb variable?

  cb('1');
  ^

ReferenceError: cb is not defined
    at insideFunc (file:///usr/src/app/file.js:42:3)
    at mainFunc (file:///usr/src/app/file.js:38:3)
    at file:///usr/src/app/file.js:46:1
about 4 years ago · Juan Pablo Isaza
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!