Undefined vs Not Defined vs Null in Javascript
Undefined
1) undefined is a global variable that JavaScript creates at run time.
2) whenever we declare any variable in our code without assigning any value javascript automatically assign value undefined.
as shown in above example if variable is declared but value is not assigned then it will return undefined. but in case of array if array item is missing it will return empty.
Not Defined
- when we not define variable and its value in our code at that point of time and try to access the variable then it will return not defined.
- After that script will stop.
Null
we can assign null value in variable. btw null is the reserved word in JavaScript. when we assign null value to any variable that means we are telling JavaScript interpreter that variable has no value.
NOTE :
use typeof to know about what type of variable is.
Lets preform some arithmetic operation .