function test(number) {
while( number < 5 ) {
number++;
}
return number;
}
alert(test(2)); // returns 5.
My question is when we increment value and place + after the argument (number++) by the rule it should first return the old value and than add 1 to it. But why in the example above it return 5?
Consider the number 4. It’s less than 5 so it meets the condition of the while loop, and the 4 gets increased to a 5. When the condition is checked again, 5 is not less than 5, so the while loop ends, and the 5 is returned.