+ 2

Why this code give output as 6?? Solved

let x=0; for(let i=0;i<4;i++){ x=x+i;} console.log(x)

3rd Apr 2022, 1:46 AM
Mohd Junaid
5 Answers
+ 3
when i = 0, x = 0 i=1, x = 1 i=2, x = 3 (1 +2) // previous x and current i values i=3, x = 6 ( 3+3) // pre x = 3, current i = 3 so, 6 is the final answer what were you hoping to get?
3rd Apr 2022, 1:51 AM
NonStop CODING
NonStop CODING - avatar
+ 1
Now i understood....
3rd Apr 2022, 1:53 AM
Mohd Junaid
+ 1
Thanks bruhh!
3rd Apr 2022, 1:53 AM
Mohd Junaid
0
close the casešŸ‘
3rd Apr 2022, 1:54 AM
NonStop CODING
NonStop CODING - avatar
0
edit your question and write [ Solved ] in front of it
3rd Apr 2022, 1:55 AM
NonStop CODING
NonStop CODING - avatar