來自非javascript背景,我試圖圍繞'未定義'我的頭。 我寫了一個「isUndefined」功能如下:瞭解功能和undefined
function isUndefined(value) {
return (typeof value === 'undefined');
}
,如果我在源類型本(其中變量「噓」不存在),我得到預期的結果「未定義的變量」。
if (typeof boo === 'undefined') {
console.log('undefined variable');
}
,如果我在下面輸入: console.log (isUndefined(undefined));
我得到預期的結果 '真'
如果我輸入:console.log(isUndefined(boo));
我得到:
Reference Error: boo is not defined.
我希望得到'真實' - 所以我的問題是爲什麼第一個'直接'檢查undefined會返回預期的結果,但是函數()對它的測試不會呢?
你是對被這個莫名其妙。 –
你來自哪些背景? – galchen
http://javascriptweblog.wordpress.com/2010/08/16/understanding-undefined-and-preventing-referenceerrors/ – goat