Javascript Errors
Javascript Errors
1. Syntax Errors:
- These occur when the JavaScript parser encounters syntax that does not conform to the
language rules.
- Example Code:
console.log("Hello World!;
2. Reference Errors:
- Occur when a non-existent variable is referenced.
- Example Code:
3. Type Errors:
- Occur when a variable or parameter is not of a valid type.
- Example Code:
let x = 5;
4. Range Errors:
- Occur when a value is not in the set or range of allowed values.
- Example Code:
eval is discouraged.
- Example: Using eval incorrectly.
6. URI Errors:
- Occur when there is an issue with the use of URI handling functions (encodeURI, decodeURI).
- Example Code:
7. Logical Errors:
- Occur due to flaws in the program logic.
- Example: Writing code that runs but does not produce the expected output.
- Example Code:
- Example Code:
9. Custom Errors:
- Developers can define their own error types for specific cases.
- Example Code:
constructor(message) {
super(message);
this.name = "CustomError";
}
throw new CustomError("This is a custom error!");
Example:
try {
let num = x / 0;
} catch (error) {
} finally {