Just testing for const support in browsers, so I need to catch syntax errors, which 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.");
}
}
Cheers.
Edit: Sorry for duplicate. Like epascarello solution better anyway. Avoids eval.