Learn JavaScript
Error Handling

Error Object in try...catch

In case of an error, JavaScript generates an error object. The error object contains the details about the error. It is then passed to catch as an argument.

The name property in the built-in error object gives the name of the error and the message property gives the details about the error.

In the example given below, the err variable stores the error object. We can access its properties using the dot operator.