【发布时间】:2021-10-20 07:55:12
【问题描述】:
代码:
function sumfunct(x,y)
{
let sum = 0;
sum = (x === null ? 0 : x) + (y === null ? 0 : y);
return sum;
}
如果其中一个输入值为 null,则返回 Nan
请帮我返回一些值
【问题讨论】:
-
如果调用函数时不带一个或多个参数,则函数中的值为
undefined,而不是null。 -
1)
undefined === null => false; 2)1 + undefined => NaN
标签: javascript node.js conditional-operator