As a programmer encountering errors in code is inevitable . As errors are a natural part of the coding process, we go through different types of errors. So as a programmer, we have to learn to deal with them and troubleshoot the errors which come while we code.
In this blog, we will learn about 2 variants, the Type Error and the Reference Error.
Type Error
A Type Error occurs when you try to use a value or variable of a different type. So basically it's an error that happens when you try to use something as the wrong type. It may also occur when you inappropriately use a value or modify a value that cannot be changed.
Example :
In this example, we declared a variable 'number' and assigned the value 42 to it. So now when we call the 'number' as a function we get ' TypeError ' because it's a number and not a function.
Reference Error
Reference Error occurs when we try to use a variable or function that hasn't been declared. This can happen when you misspell a variable name or function name or when you try to use a variable or a function that is out of scope.
Example :
In this example, we try to log the value of a variable called 'yash' but we never declared it anywhere. This will give us a reference error because the variable doesn't exist.