What browsers currently support JavaScript's 'let' keyword?

前端 未结 7 2179
悲哀的现实
悲哀的现实 2020-11-27 16:29

I\'m developing an app and don\'t have to ever worry about Internet Explorer and was looking into some of the features present in A+ grade browsers that aren\'t in Inte

7条回答
  •  暖寄归人
    2020-11-27 16:44

    As of April 2017:

    • All up-to-date major browsers such as Chrome, Firefox, and Edge support the ES2015 (aka "ES6") let keyword.

    • iOS Safari did not support let until OS 10 (e.g, OS 9 did not).

    • Some older browsers, such as IE9-IE11, support an early version of let but don't support the semantics defined by ES2015 (particularly in relation to declarations in the headers of for loops). So it's not a syntax error, and it does declare the variable, but it doesn't work the way it's supposed to. For instance, in a correct implementation, the following logs 0, 1, and 2; on IE9-IE11, it logs 3, 3, 3:

       for (let i = 0; i < 3; ++i) {
            setTimeout(function() {
                console.log(i);
             }, i * 100);
        }
       

    • Obsolete browsers such as IE8 do not support it at all.

提交回复
热议问题