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

140
Visualizações
Prefix and postfix operators
let a = 70;
a++; // This returns the value before incrementing.
console.log(a) // returns 71

Can someone explain to me why this doesn't return 70, please?

let b = 70;
++b; // Using it as a prefix returns the value after incrementing.
console.log(b) // returns 71

I understand how prefix works.

I have read explanations and watched videos on this subject but it's still confusing to me. Thank You.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

"return" isn't the right term (functions return, expressions do not).

a++ evaluates as the value before incrementing.

You aren't looking at the value the expression evaluates as, you are just looking at the value of the variable after the increment.

let a = 70;
let result_of_a_plus_plus = a++; // This evaluates as the value before incrementing.


let b = 70;
let result_of_plus_plus_b = ++b; // Using it as a prefix increments the value before the expression is evaluated.

console.log({
  a,
  result_of_a_plus_plus,
  b,
  result_of_plus_plus_b
});

about 4 years ago · Juan Pablo Isaza Relatório

0

Both versions of them increment the value they're applied to. If you do nothing with the value of the increment expression itself, they're equivalent, both of them doing the same thing as i += 1. The only time it matters is when you use the result of the increment expression:

let a = 70;
console.log(a++); // outputs 70, the old value of a, but a will be 71 afterwards
console.log(a)    // outputs 71; no matter how you increment, after the increment, the value has changed

let b = 70;
console.log(++b); // outputs 71; the new value of b is produced
console.log(b)    // outputs 71; same as in case a
about 4 years ago · Juan Pablo Isaza Relatório

0

The difference you are trying to notice is only visible when you use these prefix/postfix operators inline, something like this:

let a = 5;
console.log(a++);
let b = 5;
console.log(++b);
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