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

109
Vistas
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
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