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

108
Views
Javascript closure explanation for newbie

So i came across some closure examples, and i would like to know how does this work. I solved it by mistake and after a few hours of trying. but i am still trying to understand how the values are passed. I understand that once i create a local variable (func) the value associated with it doesnt really change, so i can keep referencing that initial value. My question is how when i return the inner function i am able to transfer the values in logArea to the callback function. can someone explain like step by step?

const wrapLog = function(callback, name) {
  let func = callback;
  return function(...param) {
    return func(...param);
  }
};

const area = function(x, y) {
  return x * y;
};

const logArea = wrapLog(area, "area");

console.log(logArea(5, 3)); // area(5, 3) => 15
console.log(logArea(3, 2)); // area(3, 2) => 6

const volume = function(x, y, z) {
  return x * y * z;
};

const logVolume = wrapLog(volume, "volume");

console.log(logVolume(5, 3, 2)); // volume(5, 3, 2) => 30
console.log(logVolume(3, 2, 4)); // volume(3, 2, 4) => 24

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!