Skip to content
Related Articles

Related Articles

Improve Article

JavaScript EvalError Object

  • Last Updated : 25 May, 2021

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 occured
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
Recommended Articles
Page :