0

why?

hi i have trouble of memory number++ means number+1 or 2 right? why here; function test(number) { while(number < 5) { number++; } return number; } alert(test(2)); the result is not 3 or 4 ?

22nd Jul 2020, 10:02 PM
zike
2 Answers
+ 2
number++ means number+1 Answer should be 5
22nd Jul 2020, 10:14 PM
Abhay
Abhay - avatar
+ 2
number++ is equivalent to number=number+1. You are using a while loop in the loop you declared number++. When number==5 the while loop stops. That's why the result is 5.
23rd Jul 2020, 1:35 AM
The future is now thanks to science
The future is now thanks to science - avatar