我有下面的代码:第二个条件与空值
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