Possible Duplicate:
What is “undefined x 1” in JavaScript?
In Chrome 21, feeding [,]
to the console outputs
[undefined x 1]
and feeding [undefined]
outputs
[undefined]
What is the difference between [undefined]
and [undefined x 1]
?
What is the notation [undefined x 1]
?
The main difference between "undefined" and "not defined" is that "undefined" is a value that can be assigned to a variable, while "not defined" indicates that a variable does not exist.
It means null is equal to undefined but not identical. When we define a variable to undefined then we are trying to convey that the variable does not exist . When we define a variable to null then we are trying to convey that the variable is empty.
The undefined value is a primitive value used when a variable has not been assigned a value. The null value is a primitive value that represents the null, empty, or non-existent reference.
A variable that has not been assigned a value is of type undefined . A method or statement also returns undefined if the variable that is being evaluated does not have an assigned value. A function returns undefined if a value was not returned .
[,]
is a sparse array. It has a length of 1
, but no values (0 in [,] === false
). It can also be written as new Array(1)
.
[undefined]
is an array of length 1
with the value undefined
at index 0
.
When accessing the property "0
", both will return undefined
- the first because that property is not defined, the second because the value is "undefined". However, the arrays are different, and so is their output in the console.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With