JS-008

Beginner2 min~2 min read#undefined#primitive-types#variables
undefined
Not assigned yet
Goal
Learn what undefined means in JavaScript.
Explanation
- undefined means a value has not been assigned yet.
- If you create a variable without a value, JavaScript automatically assigns undefined to it.
- Unlike null, undefined does not need to be written manually.
- This means the variable exists but does not contain anything yet.
- undefined is common while writing and debugging programs.
Analogy
Imagine an empty box that nothing has been put into yet. Nobody has even decided what should go inside. That is undefined.
Code
let age;
console.log(age);Result: undefined
Common mistake
Many beginners think undefined and null mean the same thing. In reality, they serve different purposes.
Remember
- ✦ undefined means a value has not been set yet.
- ✦ JavaScript can assign undefined automatically.
- ✦ undefined and null are different values.
Quick Quiz
When does JavaScript automatically return undefined?