Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Template literals syntax is not working in IE11

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 }

like image 848
usefulBee Avatar asked Nov 29 '16 17:11

usefulBee


People also ask

Does IE11 support template literals?

If you look at the ECMAScript 6 compatibility table, you'll see that template literals are not supported by IE11.

Why template literal is not working?

If you are using JavaScript's new template literal syntax in a JSP page it might not work as expected. That's because JSP and JavaScript both use the ${myVar} syntax.

How do you write template literals?

Description. Template literals are enclosed by backtick (`) characters instead of double or single quotes. Along with having normal strings, template literals can also contain other parts called placeholders, which are embedded expressions delimited by a dollar sign and curly braces: ${expression} .


1 Answers

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.

like image 60
Michał Perłakowski Avatar answered Sep 20 '22 17:09

Michał Perłakowski