Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

117
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda