Open In App

Aptitude | JavaScript Course Quiz 3 | Question 1

Like Article
Like
Save
Share
Report

What will be the output of the following code? 

JavaScript




<script>
let result = 0;
for (let i = 0; i < 5; i++) {
  result += i;
}
document.write(result);
</script>


(A)

5

(B)

0

(C)

10

(D)

None of the above


Answer: (C)

Explanation:

The loop will run from 0 to 4, thus adding 0+1+2+3+4 = 10. So, the answer will be 10.


Quiz of this Question
Please comment below if you find anything wrong in the above post


Last Updated : 10 May, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads