Creating An Error Message If Browser Does Not Support ES6 Template Literals
I have been using string literals in my javascript. I would like an error message to be shown if string literals are not supported. caniuse My Idea was that i would create a funct
Solution 1:
Yes. This is one of the legitimate uses of eval
:
var supportsTemplateLiterals = false;
try {
eval("`foo`");
supportsTemplateLiterals = true;
}
catch (e) {
}
console.log("Supports template literals? " + supportsTemplateLiterals);
It works because the main code parses on a pre-ES2015 JavaScript engine, but the code in the eval
doesn't; parsing chokes on the template literal.
On Chrome, Firefox, Edge, etc, that shows
Supports template literals? true
On IE (any version), it shows:
Supports template literals? false
Post a Comment for "Creating An Error Message If Browser Does Not Support ES6 Template Literals"