The pre-increment and post-increment results the same but the only difference is the result of evaluating the expression.
++i : increments i and evaluates the new value of i.
i++ : evaluates the old value of i and then increments i.
for(var i=0;i<=10;i++){
console.log(i);
}
for(var i=0;i<=10;++i){
console.log(i);
}
Result for both for loops :
0
1
2
3
4
5
6
7
8
9
10
++i : increments i and evaluates the new value of i.
i++ : evaluates the old value of i and then increments i.
for(var i=0;i<=10;i++){
console.log(i);
}
for(var i=0;i<=10;++i){
console.log(i);
}
Result for both for loops :
0
1
2
3
4
5
6
7
8
9
10
No comments:
Post a Comment