Course Content
Introduction to JavaScript
4. Conditional Statements
Introduction to JavaScript
null
The null
is "nothing". We use the null type to tell the interpreter that our variable has no data (define "nothing").
The example above demonstrates that the null
type produces no output in the console.
Note
null
is distinct fromundefined
.- We use
null
when we need to:
- pass empty data to another program and signify that the data is empty;
- define empty data within our code.
For instance, if you need to describe a hero's data in a game, you should use the null type for unknown or missing data. Imagine another program queries your program for the hero's name, but if the variable containing the name doesn't exist, it will result in an error. Using the null type indicates that the hero has no name and can be passed to another program as such.
We won't delve into real-world examples, as they can be pretty complex and specific to Frontend development. For now, it's essential to remember this data type.
Everything was clear?