问:
var textToDisplay; // = "testing";
textToDisplay = "testing";
textToDisplay = 1;
var someNumber = 1;
var oneMoreNumber;
oneMoreNumber += textToDisplay + someNumber; //results in NaN
console.log(oneMoreNumber);
这里的结果是NaN?
回答:
是的,结果是NaN
因为当你定义oneMoreNumber的时候没有给赋值,所以自动判定为undefined,当使用+=的时候,
oneMoreNumber = undefined + "testing" + 1
所以结果为NaN而不是你认为的testing1.