You can test to see if an error is indeed a SyntaxError.
try {
eval(code);
} catch (e) {
if (e instanceof SyntaxError) {
alert(e.message);
}
}
More Related Contents:
- Why is using the JavaScript eval function a bad idea?
- When is JavaScript’s eval() not evil?
- Executing elements inserted with .innerHTML
- Convert a string to a template string
- Are eval() and new Function() the same thing?
- Calculate string value in javascript, not using eval
- (1, eval)(‘this’) vs eval(‘this’) in JavaScript?
- Why does JavaScript’s eval need parentheses to eval JSON data?
- Is it possible to achieve dynamic scoping in JavaScript without resorting to eval?
- Why {} + {} is NaN only on the client side? Why not in Node.js?
- Is Javascript eval() so dangerous? [duplicate]
- Specify scope for eval() in JavaScript?
- Eval is evil… So what should I use instead?
- what does eval do and why its evil? [duplicate]
- Safely sandbox and execute user submitted JavaScript?
- Accessing or creating nested JavaScript objects with string key without eval
- Restricting eval() to a narrow scope
- Why the open quote and bracket for eval(‘(‘ + jsonString+ ‘)’) when parsing json string
- What are the Alternatives to eval in JavaScript?
- How to code a calculator in JavaScript without ‘eval’
- Context-preserving eval
- Alternatives to JavaScript eval() for parsing JSON
- What’s the main benefit of using eval() in JavaScript?
- Alternative to eval() javascript [duplicate]
- Exploiting JavaScript’s eval() method
- JQuery getJSON – ajax parseerror
- Injecting JS functions into the page from a Greasemonkey script on Chrome
- How to bundle vendor scripts separately and require them as needed with Webpack?
- Alter and Assign Object Without Side Effects
- Angular url plus sign converting to space