New course! Every coder should learn Generative AI!
Try a free lesson+ 3
[DUPLICATE] Help me to understand Increment and Decrement In javascript
Please, help me To understand the pre and post increment and decrement in JavaScript. And please, explain what the differences between ++i, i++ and how I will use that. Thanks, A lot. [ Please, only answer for JavaScript]
1 Answer
+ 9
https://www.sololearn.com/Discuss/98959/?ref=app
The prefix and postfix definitions / operation are the same between languages.
This answer by https://www.sololearn.com/Profile/2476881/?ref=app would apply equally.
_____
++x increments the value of x and then returns x
x++ returns the value of x and then increments
for example:
int a=0;
cout << a++;
// var a=0;
// console.log(a++);
the output will be still 0, as it uses the value of a and only then adds 1. But if we look at the following example:
int b=0;
cout << ++b;
//var b=0;
//console.log(++b);
the output will be 1, as it adds 1 before using the value of b... but after both codes will be executed, the value of a and b will be 1.