I was just testing this on javascript and noticed that each time I return a variable with a ++, it didn't return the new number. I know the ++ is added after, but shouldn't be added before returning it. When I debugged it, is showing the correct number, but when returning it doesn't. Does the interpreter executes this line after the return? If it's like that why the debugger shows the correct value?
This function returns the correct number without the ++. It returns 10.
function test(){
var counter=0;
for(i=0;i<10;i++){
counter++;
}
return counter;
}
This other function, I thought it should return 11, but it doesn't it returns 10.
function test1(){
var counter=0;
for(i=0;i<10;i++){
counter++;
}
return counter++;
}
Demo showing this example.