If you've been programming for a while, these terms might be familiar to you and not in the good sense. Usually we find these words written in red text with a whole bunch of errors. Now this article won't be focused on those errors but more so on what these 3 keywords mean and how they differ from each other.
Let's start off with null
. null is an actual value that can be given to a variable. It is similar to saying a variable is empty.
Secondly we have undefined
. Undefined is an error that is thrown when the programmer is trying to assign or use a variable without having first declared it. Nowadays with ES6's new let
and const
, these undefined
's are much easier to spot. Back before ES6, there would be a lot of silent errors that would occur with the var
keyword and how it hoisted itself.
Lastly, we have a more uncommon error, undeclared
. With the release of ES6, these errors have been seen a lot less as for this error occurs when you try to assign a value to a variable that has not been declared with var.
Top comments (0)