Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

let statement in loop doesn't work as expected in IE

I am trying some example in ECMAScript 6. That is working differently compared to other browsers. This returns true in Firefox, but it returns false in IE. Why is this working different in Internet Explorer?

let callbacks = []
for (let i = 0; i <= 2; i++) {
  callbacks[i] = function () { console.log(i); return i * 2 }
}
console.log(callbacks[0]() === 0);
console.log(callbacks[1]() === 2);
console.log(callbacks[2]() === 4);
like image 570
Raavanan Avatar asked Aug 26 '16 06:08

Raavanan


1 Answers

According to caniuse.com IE11 kind of supports let:

let variables are not bound separately to each iteration of for loops

like image 55
Peter Zilz Avatar answered Oct 11 '22 11:10

Peter Zilz