In JavaScript, when you declare a variable but don't assign it a value, it automatically gets a special value called undefined.
↗️
Loading editor...
↶
↷
undefined means the variable exists, but has no value yet. It's JavaScript's way of saying "I know about this variable, but nothing has been put in it."
undefined is a type AND a value
In JavaScript, undefined is both a type and the only value of that type. When a variable is undefined, its type is also undefined!
You'll see undefined in these situations:
- When you declare a variable without assigning a value
- When you access a property that doesn't exist on an object