Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript EvalError Object

Improve Article
Save Article
  • Last Updated : 08 Jun, 2022
Improve Article
Save Article

There are several types of errors that we encounter in JavaScript, for example, SyntaxError, RangeError, ReferenceError, EvalError, etc. The EvalError indicates an error regarding the global eval() function. 

Newer versions of JavaScript however do not throw EvalError.

Syntax:

new EvalError()
new EvalError(message)

Parameters: The message is an optional parameter that provides details about the exception that occurred.

Return value: A newly constructed EvalError object.

Below are some examples of JavaScript EvalError.

Example 1:

Javascript




<script>
  try {
    throw new EvalError('EvalError has occurred');
  } catch (e) {
    console.log(e instanceof EvalError);
    console.log(e.message);            
    console.log(e.name);               
  }
</script>

Output:

true
EvalError has occurred
EvalError

Example 2:

Javascript




var score={
  checkerror:function (score){
    if(score<0)
    {
       try{
         throw new EvalError('Error occurred');
       }catch(e)
       {
          console.log(e.message);
       }
        
    }
  }
}
console.log(score.checkerror(-3));

Output:

Error occurred
undefined

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!