2011-05-15 112 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