What will be the output of the following JavaScript code? [code] var a= 0; var b = 0; while (a < 3) { a++; b += a; console.log(b); }[/code]

What will be the output of the following JavaScript code?
Code:
var a= 0;
var b = 0;
while (a < 3)
{
  	a++;
  	b += a;
	console.log(b);
}
A. 135
B. 123
C. 013
D. 01
 
Answer: a
Explanation: A while loops checks for the condition first before executing the looping statements. A while loop increments the value at the end of the loop whereas for executes the statement at the starting of the loop.
 

Tìm kiếm

Back
Top