0
what us the output of the code below plz explain it briefly I don't understand how the output is 5
function test(x){ while(x<5){ x++; } return x; } alert(test(2))
5 odpowiedzi
+ 1
The function keeps up adding one to the number until it reaches five and thus it returns five as the output.
+ 2
Beamlak Amare , the while loop runs until false condition is met. When the value becomes 5 the loop stops and the function returns the value which is shown in the alert box.
+ 1
Beamlak Amare , the last step is when x is 4 => 4 < 5 is true, x is increased and becomes 5. But 5 < 5 is false => the loop stops.
0
but why does it output 5 because x<5
0
so it outputs 5 because it is where it stops?