Of course, this is more of a trick question. However, such questions force you to focus on reading the code better. Here, the variable i
is defined using var
so it is function scoped and the variable number
is a global variable and is updated on every loop iteration.
Now, a lot of people might mistake and choose Option 4
as the loop will break when i
becomes 5
. However, in this case, the variable number
would not be updated when i = 5
. Hence, the code will print 4
five times.