我有下面的代碼:第二個條件與空值
function listToArray(list) {
var array = [];
for(var node = list; node; node = node.rest) {
console.log(node.rest);
array.push(node.value);
}
return array;
}
例如: - 像[1, 2, 3]
數組看起來以列表的形式這樣{ value: 1, rest: { value: 2, rest: { value: 3, rest: null }}}
。
函數中for循環的條件最終將導致null
。我的問題是,這個有條件的工作如何?通常你會有一個布爾表達式,例如:i <= 10
。 AFAIK,null
沒有評估到一個虛假的價值......那麼,有條件的工作如何?
'null' *爲* falsey在JavaScript中JS – alex
Falsy值:'FALSE','0',空字符串,'null','undefined','NaN'。 – Barmar
爲什麼標題說**第二**有條件?代碼中只有一個條件。 – Barmar