当我尝试使用undefined
运行以下动态生成的javascript时,会返回eval()
。如果删除if/else
语句,它将返回0
,但是当我尝试使用if/else
语句时,它将返回undefined
。
function doCalculation() {
var OfferSupport=0;
var DOOfferSupport=4;
var SupportFull=SupportFull;
var SupportNone=SupportNone;
if(DOOfferSupport >= 1)
OfferSupport = SupportFull ;
else
OfferSupport = SupportNone ;
return OfferSupport;
}
console.log('test: ' + doCalculation());
谁能告诉我为什么?
最佳答案
您要将变量设置为SupportFull
或SupportNone
,这两个变量均未定义。
如果要取回值,则需要设置一个值。