Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
JavaScript Error message Property
The message property of JavaScript Error objects contains a human-readable description of the error. It's automatically set when an error occurs and can also be customized when creating custom errors.
Syntax
error.message
Example: Accessing Error Message
JavaScript Error message Property Click the button to see the error message
Creating Custom Error Messages
Custom Error Messages
Common Error Types and Messages
| Error Type | Example Message | Cause |
|---|---|---|
| ReferenceError | "variable is not defined" | Using undefined variables |
| TypeError | "Cannot read property 'x' of null" | Accessing properties on null/undefined |
| SyntaxError | "Unexpected token" | Invalid JavaScript syntax |
| Custom Error | Your custom message | Thrown with new Error() |
Key Points
- The
messageproperty is read/write - you can modify it after creating an error - Different browsers may format error messages slightly differently
- Custom error messages should be descriptive and user-friendly
- The message property doesn't include the error type - use
error.namefor that
Conclusion
The message property provides essential error information for debugging and user feedback. Use it in try-catch blocks to handle errors gracefully and create meaningful custom error messages.
Advertisements
