"undefined"和"undefined"之间有什么区别?和未定义? [英] What is the difference between "undefined" and undefined?

查看:51
本文介绍了"undefined"和"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.

推荐答案

    在大多数情况下,
  1. undefined 实际上是 window.undefined .这只是一个变量.
  2. window.undefined 发生在未被定义,除非有人对其进行定义(尝试 undefined = 1 typeof undefined 将是数字" ).
  3. typeof 运算符,该运算符始终返回字符串,描述值的类型.
  4. typeof window.undefined 为您提供"undefined" -同样,只是一个字符串.
  5. typeof"undefined" 给出"string" ,就像 typeof"foo" 一样.
  6. 因此, typeof typeof undefined 给出了"string" .
  1. undefined is actually window.undefined in most situations. It's just a variable.
  2. window.undefined happens to not be defined, unless someone defines it (try undefined = 1 and typeof undefined will be "number").
  3. typeof is an operator that always returns a string, describing the type of a value.
  4. typeof window.undefined gives you "undefined" - again, just a string.
  5. typeof "undefined" gives "string", just like typeof "foo" would.
  6. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆