Template literals syntax is not working in IE11

╄→尐↘猪︶ㄣ 提交于 2019-12-17 12:14:06

问题


The back-tick character is not recognized as a Valid Character in IE11 when using the "use strict" directive while it works in other browsers, such as Chrome.

What is the interpretation of this behavior taking into consideration that IE11 is still widely used even among Windows 10 users??

        "use strict";

        function doIt() {
          let tt;
          tt = 50;
          alert(`${tt}`);
          alert("test");
        }
       doIt();

Error: { "message": "Invalid character", "filename": "http://stacksnippets.net/js", "lineno": 18, "colno": 17 }


回答1:


If you look at the ECMAScript 6 compatibility table, you'll see that template literals are not supported by IE11. The "use strict"; statement doesn't really change anything, because before it is determined whether a code is in strict mode, it has to be parsed first, but it can't be parsed, because you're using syntax that the parser doesn't recognize.

If you want your code to work in IE11, you should transpile it with Babel.



来源:https://stackoverflow.com/questions/40871705/template-literals-syntax-is-not-working-in-ie11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!