What is the difference between using ++ or - - in front of or behind a variable? [duplicate]

1

Having this variable:

var edad = 22;

We apply the unary operators: ++ and - -, both before and after the variable, in the following way:

console.log(++edad); \ 23.

console.log(--edad); \ 21.

If we apply at the end:

console.log(edad++); \ 22.

console.log(edad--); \ 22.
  

What is the difference between the two of them to give such results?

    
asked by Victor Alvarado 29.04.2017 в 17:09
source

1 answer

4

I leave you a commented code: review the results, take into account the actions before and after

var numero=10;


console.log(numero++);// primero lo muestra, muesta el valor actual y luego lo suma 1
console.log(numero); //muestra el valor actual


console.log(++numero);//primero lo suma y luego lo muestra
console.log(numero); //muestra el valor actual
    
answered by 29.04.2017 в 17:20