"undefined"和"undefined"之间有什么区别?和未定义? [英] What is the difference between "undefined" and undefined?
问题描述
我正在Chrome控制台中尝试以下测验:测验
I'm trying this quiz in the Chrome console: Quiz
尝试一下后,我可以对其中的大多数进行一些解释.但是有一件事使我感到困惑:
I can explain most of them somewhat after trying them out. But one thing confuses me:
var x = [typeof x, typeof y][1];
typeof typeof x;
....返回字符串",这对我来说没有任何意义.
.... returns "string", which doesn't make any sense to me.
var x = [typeof x, typeof y][1];
返回未定义"
typeof"undefined"
返回字符串",这是有道理的,因为未定义是用引号引起来的.但是总的来说,我看不到未定义"与未定义共存的目的.另外,那是什么样的数组语法?"Javascript The Good Parts"说没有多维数组.
returns "string", which makes some sense because undefined was in quotes. But overall, I don't see the purpose of "undefined" in coexistance with undefined. Also, what kind of array syntax is that? "Javascript The Good Parts" says that there are no multidimensional arrays.
推荐答案
- 在大多数情况下,
-
undefined
实际上是window.undefined
.这只是一个变量. -
window.undefined
发生在未被定义,除非有人对其进行定义(尝试undefined = 1
和typeof undefined
将是数字"
). -
typeof
是运算符,该运算符始终返回字符串,描述值的类型. -
typeof window.undefined
为您提供"undefined"
-同样,只是一个字符串. -
typeof"undefined"
给出"string"
,就像typeof"foo"
一样. - 因此,
typeof typeof undefined
给出了"string"
.
undefined
is actuallywindow.undefined
in most situations. It's just a variable.window.undefined
happens to not be defined, unless someone defines it (tryundefined = 1
andtypeof undefined
will be"number"
).typeof
is an operator that always returns a string, describing the type of a value.typeof window.undefined
gives you"undefined"
- again, just a string.typeof "undefined"
gives"string"
, just liketypeof "foo"
would.- Therefore,
typeof typeof undefined
gives"string"
.
关于此语法:
In relation to this syntax:
[1, 2][1];
那不是多维数组-它只是先创建一个数组 arr = [1,2]
,然后从中选择元素1: arr [1] 代码>.
That's not a multi-dimensional array - it is merely creating an array first arr = [1, 2]
, and then selecting element 1 from it: arr[1]
.
这篇关于"undefined"和"undefined"之间有什么区别?和未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!