Understanding undefined in JavaScript
In JavaScript, undefined is a primitive value automatically assigned to variables that have been declared but not initialized. It also represents the absence of a value in certain cases.
When does undefined occur?
1. Declaring a variable without assigning a value:
2. Accessing an object property that does not exist
3. Accessing an array element outside its bounds
4. A function without a return statement or returning nothing
5. Function parameters that are not provided
Difference Between undefined and null
• undefined means a variable has been declared but not assigned a value.
• null is an intentional absence of any object value, usually assigned explicitly.