3 Most Common JavaScript Errors & What they mean
I know we’ve all been at a point where we are doing a lab, a project, or trying to follow along in a lecture and have run into certain errors we just didn’t understand, especially certain errors in JavaScript because they all almost seem alike in a way unless you read carefully. So in this article i’ll be going over the 3 most common errors i’m pretty sure we’ve all run into dealing with JavaScript.
1. Uncaught TypeError: cannot read property
I’m 100% sure this was probably the first error everyone has encountered on JavaScript & here’s why. This error here happens when a certain variable has been declared but not assigned a value, so its basically telling you it can’t recognize the the variable you are trying to impose in your code. This one is probably one of the easiest to read out of any error because it will highlight what variable can’t be declared.
2. TypeError: Undefined is not an object
This error here is honestly almost the same as the first error I explained but it is written out differently if you are using safari instead of chrome, also it occurs when you call a method on an undefined object so the message will appear as null.
3. TypeError: null is not an object
Speaking about null from the 2nd error, this error occurs when you try to call a method on a ‘null’ object, so like calling a declared variable with an empty value. It was given a value but nothing was written for it, then this error message will appear. The difference with this and the 2nd error is that ‘undefined’ & ‘null’ are actually two completely different things when it comes to JavaScript, ‘Undefined’ is when a variable has not been given a value and again ‘null’ is when a variable has an empty value.This error also occurs when DOM elements are not created before loading the script.
Now that I have explained the 3 most common errors known in JavaScript, I hope you remember this article (also this meme ^) when you see an error occur and remember exactly what they mean and how to avoid them.