What does i++ and i-- mean?

Question

What does i++ and i-- mean?

Answer

The ++ and -- are the increment and decrement operators, respectively. The increment operator adds 1 to the operand and the decrement operator subtracts 1 from the operand.

Increment example:

let x = 10;
while(x < 20) { //when x is less than 20
  x++; //add 1 to x
  console.log(x); //logs the numbers 11 - 20 to the console
}

Decrement example:

let x = 10;
while(x > 0) { //when x is greater than 0
  x--; //subtract 1 from x 
  console.log(x); //logs the numbers 9 - 0 to the console
}
2 Likes