【发布时间】:2013-10-15 08:01:48
【问题描述】:
为什么我可以在 .push() 函数中执行 if else shorthand ?喜欢
var arr = [];
arr.push(test||null);
// nothing
但是
var arr = [];
var test = test||null;
arr.push(test);
// [null]
如果变量未定义,我需要插入null。
为什么我不能在.push() 函数中使用test||null?
【问题讨论】:
-
您的第一个示例导致错误,这就是为什么没有任何反应。请看一下控制台。
标签: javascript arrays if-statement push array-push