Consider the following code:
var x = undefined;
It's a self-contradicting line of code. Is x defined or not? Do implementations of JavaScript remove the variable x
from memory, or do they assign it the value undefined
?
Consider the following code:
var x = undefined;
It's a self-contradicting line of code. Is x defined or not? Do implementations of JavaScript remove the variable x
from memory, or do they assign it the value undefined
?
There's a difference between a variable being undeclared and being undefined:
var x; //x is equal to *undefined*
alert(y); //error, y is undeclared
This isn't self-contradicting, but it is redundant:
var x = undefined;
Think of undefined
as simply the value a variable has when it hasn't been initialized – or the value an object property has when it hasn't been initialized or declared.