What is an error ?
- syntax errors : This error occurs when there is something incorrect in the syntax of the program.
- runtime errors : This error occurs during the runtime of the program after it's interpreted by the compiler.
- logical errors : This error occurs when the syntax is correct but the logic is not.
Let us explore types of errors :
- This is most common error occured.
- This error occurs when we use already predefined syntax incorrectly.
- for example
here 's' is the unexpected identifier.
- This error occurs when the value does not turns out to be of a particular expected data type.
- Means when method is called or reads a property on wrong data type or undefined object.
- State is not initialize properly when UI is rendered, this could be one of the reason. This leads to unsuccessful operation
- This error also occurs when a variable is used outside its own data type scope. Following are some examples of typeErrors :
- This error is received when reference of the variable cannot be found or variable is used outside the current scope.
- Also this error is received when you use a variable which is not declared.
- Whenever we try to use a variable during temporal dead zone, this error is received. Temporal dead zone is a time period between when the variable is hoisted and it is assigned with some value.
- In the first example 'a' was not defined.
- And in the second example we tried to access this 'name' in its Temporal dead zone i.e, it was hoisted but not initialize with some value, thus this error occurs. To avoid this error keep all the variable and function deaclration at the top of the program. like this
- This error occurs when we try to set a variable outside its defined range and when we pass a value to a function that is out of range.
- Or when we call a recursive function that does not terminate.
- URIError (Uniform Resource Indicator) is thrown when there is a problem in encoding and decoding the URI.
- URI in JS have functions : decodeURI, decodeURIComponent, etc. If we use any of them with the wrong parameter we will get a URIError.
- Here decodeURI takes encoded URI and if it containes any invalid character is throws an error.
- An EvalError occurs when an error occurs with an eval() function call.
- The spike in workload happens when there is too much data to handle.
- This occurs when the JS engine is overwhelmed by too many recursions and switch cases, etc.
I hope now you understand what these errors actually mean. Share your feedback in the comment about the blog. Have a nice day!