I don\'t get it why  i in fillArray method ends up  being equal to 10 even though the array score is filled only up to index 9>         
        
in For loop, increment occurs after testing loop condition, not before. So in last iteration when your condition is checked, I is already equal to 10 and that is exactly what is being returned. Consider this, if your I would still be 9 in last iteration, your condition would still be true which would mean one more execution in loop.