当我尝试使用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());
谁能告诉我为什么?
答案 0 :(得分:4)
您将变量设置为SupportFull
或SupportNone
,这些都是未定义的。
如果您想要取回一个值,则需要设置一个值。
答案 1 :(得分:2)
查看您的代码:
var OfferSupport=0;
var DOOfferSupport=4;
var SupportFull=SupportFull;
var SupportNone=SupportNone;
if(DOOfferSupport >= 1)
OfferSupport = SupportFull ;
else
OfferSupport = SupportNone ;
但您刚刚声明SupportFull
和SupportNone
,并没有为其指定任何值。
未定义的值
当变量尚未赋值时使用的原始值