Internet Explorer 11 JavaScript Let Statement

2020-05-09 09:06发布

问题:

I have rather complex code that is executing a multiple AJAX call in sequence through the 'for' loop. This code works because I use 'Let' statement when assigning scope to a loop index. (let i = 0; i < 2; i++) { }.

However, 'Let' is giving me " Expected ';' error in Internet Explorer 11, While the code is working perfectly in other browsers. I have tried to move "let" out of the loop but it still fails, it seem to fail wherever the statement is used regardless of the loop. Please let me know what is the workaround for this as IE 11 is supposed to be compatible with 'Let' statement.

回答1:

See this ES6 support table. Internet Explorer 11 does not support let in for/for-in loop iteration scope.

You need to take a different approach.

This answer lists a number of options you could implement manually.

You could also use a tool like Babel to transpile your ES6 or newer JavaScript into ES5.