Back to course

The Undefined Type: Implicit Absence of Assignment

JavaScript: The Complete '0 to Hero' Beginner Course

20. The undefined Type

undefined is a primitive value used when a variable has been declared but has not yet been assigned a value by the developer.

Automatic Assignment

javascript let userName; // Declared, but not initialized console.log(userName); // Output: undefined

// If a function doesn't return anything explicitly, it returns undefined: function doNothing() { /* ... */ } console.log(doNothing()); // Output: undefined

Key Difference: null vs. undefined

Featureundefinednull
MeaningValue not yet assigned (System default)Intentional absence of value (Developer assigned)
Typeundefinedobject (historical error)

Best Practice: Never explicitly set a variable to undefined. Use null if you want to explicitly clear a variable's value.