JavaScript: for loop with iterations explained