Just testing to support const in browsers, so I need to catch syntax errors that you can only do with eval.
var const_support = true;
try{
eval("const test = 'test';");
}
catch(e){
if (e instanceof SyntaxError) {
const_support = false;
}
else{
throw ("Something crazy happened.");
}
}
Greetings.
Edit: Sorry for the duplicate. In any case, like an epascarello solution. Avoids eval.
source
share