2011-05-15 41 views

回答

7
//var value; There is no var declaration. The variable was never declared 

// check againts undeclared variables 
typeof value === "undefined"; // works 

// check againts declared variables with no value 
value === undefined; // ReferenceError: value is not defined 

也有与undefined = true是有效的问题。但你并不关心这一点。这些天没有人足够愚蠢地改变undefined

我也知道instanceof被破坏的错误。我不能给你Array.isArray更好的确切原因。

如果你读this Article它提到如何instanceof不会在单独的帧/窗/ iframe的工作,你会发现在JavaScript Garden

instanceof批评。

因为instanceof会再次检查Array并且每个窗口都有自己的window.Array

+0

谢谢!我刚试过'var foo; (foo === undefined);'在我的FF4 JS控制台中没有得到引用错误。是什么赋予了? – FoobarMaximus 2011-05-15 02:45:43

+0

@FooBarMaximus如果你删除'var foo',你会得到一个引用错误;)'typeof'在没有var声明的情况下工作。 – Raynos 2011-05-15 02:51:19