[undefined]和[,]之间有什么区别? [英] What is the difference between [undefined] and [,]?
问题描述
在Chrome 21中,提供 [ ,]
到控制台输出
In Chrome 21, feeding [,]
to the console outputs
[undefined x 1]
[undefined x 1]
并且喂食 [undefined]
输出
[undefined]
[undefined]
[undefined]
和 [undefined x 1]
?
符号是什么 [undefined x 1 ]
?
推荐答案
[,]
是一个稀疏数组。它的长度为 1
,但没有值([,] === false 中的 0)。它也可以写成
new Array(1)
。
[,]
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]
是一个长度为 1
的数组,其值为 undefined
,索引为 0
。
[undefined]
is an array of length 1
with the value undefined
at index 0
.
当访问 0
属性时,两者都将返回 undefined
- 第一个因为没有定义该属性,第二个因为该值是未定义。但是,阵列是不同的,他们的控制台输出。
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.
这篇关于[undefined]和[,]之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!