new Error([message[, fileName[, lineNumber]]])
- fileName: It is the name of the file for this error object. If no name is provided than fileName is equal to the name of file containing the the code that called the Error() constructor. It is an optional parameter.
- lineNumber: It is the value for the lineNumber property on the created Error object. If no number is provided Than the lineNumber is equal to the line number containing the Error() constructor invocation. It is an optional parameter.
Example 1: Creating error object using new keyword.
Error object created successfully using new keyword
Example 2: Creating error object using function call.
Error object created successfully using function call
- Google Chrome
- Internet Explorer