To understand how the console arrived to this value, we need to re-trace the values taken by the variable i (which are added to the variable total).
First off, let’s start with boundary value: arr.length = 4 since the array consists of 4 elements (1,2,3 and 4).
Next, we are looping and stopping at i < arr.length, i.e., i < 4. Following that reasoning, i will take the successive values: 1, 2 and 3. Adding those together gives: 1+2+3=6.
Since total does just that (i.e., adds the incremental values of i), then total will have a final value of 6.