JavaScript | Error message Property
The JavaScript error message property is used to set or return the error message.
Syntax:
errorObj.message
Return Value: It returns a string, representing the details of the error.
Example 1: This example does not contains any error so it does not display error message.
<!DOCTYPE html> <html> <head> <title> JavaScript Error Message Property </title> </head> <body> <h1>GeeksforGeeks</h1> <p id="GFG"></p> <h2>JavaScript Error Message Property</h2> <!-- Script to use error message property --> <script> try { alert("A computer science portal"); } catch(err) { document.getElementById("gfg").innerHTML = err.message; } </script> </body> </html> |
Output:


Example 2: This example displays an error message when use misspelled ‘alert’ statement.
<!DOCTYPE html> <html> <head> <title> JavaScript Error Message Property </title> </head> <body> <h1>GeeksforGeeks</h1> <p id="GFG"></p> <h2>JavaScript Error Message Property</h2> <!-- Script to use error message property --> <script> try { allert("A computer science portal"); } catch(err) { document.getElementById("GFG").innerHTML = err.message; } </script> </body> </html> |
Output:

Supported Browsers: The browser supported by JavaScript Error Message Property are listed below:
- Google Chrome
- Firefox
- Internet Explorer
- Opera
- Safari
Recommended Posts:
- JavaScript | Error name Property
- How to solve “Submit is not a function” error in JavaScript ?
- Javascript | Error and Exceptional Handling With Examples
- How to pop an alert message box using PHP ?
- Message Passing in Java
- JavaScript | Math.LN2 property
- How to remove CSS property using JavaScript?
- JavaScript | Infinity Property
- JavaScript | undefined Property
- JavaScript | Cursor property
- JavaScript | multiline Property
- JavaScript | global Property
- JavaScript | Math.PI Property
- JavaScript | source Property
- JavaScript | lastIndex Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




