0

function, number++

Why is this returning 5? The following code will result in what value? function test(number) { while(number < 5) { number++; } return number; } alert(test(2)); Thank you!

8th Mar 2020, 12:15 PM
Carol
1 Answer
+ 2
number=2; while(number<5){ number++; } Loop iteration : 2<5//true number++ 3<5//true number++ 4<5//true number++ 5<5//false exit the loop Now number=5
8th Mar 2020, 12:32 PM
Prathvi
Prathvi - avatar