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

119
Vistas
curious double var case in javascript

Curious case in JavaScript where you get not exactly the most people would expect

function test() {
  var v = 2;
  var v = v++;
  console.log(v);
}
test();

Why the ++ seems ignored here? at what point the ++ operation is executed?

"v++ increments v to 3 and returns 2" what is the first, increment or return?

  • if it increments first, the returned value should be "3"
  • if it returns first 2, then after that increments, so the incremented value is 2 and v should be 3...
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

  • v is initialized with 2.
  • The expression v++ increments v to 3 and then returns 2.
  • The statement var v = v++; assigns 2 to v (overwrites the 3 in v with the 2 returned from v++).
  • console.log(v) prints 2
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