Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between [undefined] and [,]? [duplicate]

Tags:

javascript

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]?

like image 826
Randomblue Avatar asked Aug 04 '12 13:08

Randomblue


People also ask

What is the difference between undefined and undefined?

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.

Is undefined == null?

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.

What's the difference between undefined and null?

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.

What does result undefined mean?

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 .


1 Answers

[,] 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.

like image 163
Bergi Avatar answered Sep 27 '22 02:09

Bergi