var myVariable; console.log(myVariable); // Output: undefined
As you can see in the example above, we declare a variable called
myVariable but do not assign it any value. When we log the value of
myVariable, it outputs undefined.
The Difference between null and undefined
- Type: null is an object.
- Assigned Value: It is explicitly assigned to indicate that there is no value or an empty object.
- Example Usage: We can assign null to clear out the value of an object when we no longer need it.
- Type: undefined is a primitive data type.
- Assigned Value: