This is my first time writing code that actually needs to run properly on IE11 and it's not very fun.. Can anyone ascertain why i is incremented on line 6 in the below Javascript code?? Both Chrome and IE are given the same upper bound in the for loop, yet somehow the code run on explorer surpasses that upper bound? Any advice would be greatly appreciated.
console.log("headers length:", headers.length);
for (let i = 0, max=headers.length; i < max; i ++) {
console.log("i:",i);
let item = headers[i];
item.addEventListener("click", function(event){
console.log("column before func call:", i);
current_sort_column = sort_by(table, i, current_sort_column);
});
}
When run on Google Chrome:
headers length: 8
i: 0
i: 1
i: 2
i: 3
i: 4
i: 5
i: 6
i: 7
column before func call: 2
When run on IE:
headers length: 8
i: 0
i: 1
i: 2
i: 3
i: 4
i: 5
i: 6
i: 7
column before func call: 8