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

103
Vistas
Returned value not expected - closures

I don't understand why it returns 0, it is supposed to increment by 1, is there something I don't know about closures?

 let i = 0;
    const getRenderValue = function() {

      return i++;
    };
    const Component = function() {
      let hello = getRenderValue();
      console.log(hello); // return 0, expected value 1
    };
    Component();
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your closure does increment the value of i by one. If you did console.log(i); instead of console.log(hello);, you'd be seeing 1 on screen as expected.

Your closure however returns the value of i prior to the increment as it returns i++: It is a property of the postfix increment i++ that it returns i before and not after the increment. Use the prefix increment ++i if you want to return the changed value.

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