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

273
Vistas
what is the value of results for the makeCounter()

What is the value of const result? my guess was (3, 1). This is confusing to me so any help would be appreciated.

    function makeCounter() {
      let count = 0;
      return function() {
        count += 1;
        return count;
      }
    }
    const counter1 = makeCounter();
    const counter2 = makeCounter();
    counter1();
    counter1();
    
    const c1 = counter1();
    const c2 = counter2();
    const result = [c1,c2];
    console.log(result)

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Yes, [3, 1] is correct. (You can select 'run code snippit' to see it in action).

The reason here is that calling makeCounter() returns a function, with a local count variable initialized as zero.

Each time you call the the function returned by makeCounter() (i.e. counter1, or counter2), that counter's count is incremented.

counter1() is called 3 times, and counter2() is called once. And they are put together in an array at the end, thus [3, 1].

about 4 years ago · Juan Pablo Isaza Denunciar
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