What Is an Error in JavaScript?
Problem
How do errors occur and can you create an error object?
Solution
Errors result when there is a problem with code execution in the runtime . When this happens, the runtime will generate an Error object with information about what just happened. There are instances where developers can create user-defined errors that can be useful when debugging.
The Code
Listing 19-1. Two Types of Errors, One During Runtime, the Other User-Defined
new Array(-1) //returns Uncaught RangeError: Invalid array ...