+'a'
resolves to NaN
("Not a Number") because it coerces a string to a number, while the character a
cannot be parsed as a number.
(+'a'
解析为NaN
(“非数字”),因为它将字符串强制为数字,而字符a
不能解析为数字。)
To lowercase it becomes banana
.
(小写变成banana
。)
Adding NaN
to "ba"
turns NaN
into the string "NaN"
due to type conversion, gives baNaN
.
(将NaN
添加到"ba"
会由于类型转换而将NaN
变成字符串"NaN"
,得到baNaN
。)
And then there is an a
behind, giving baNaNa
.(然后是a
后面是baNaNa
。)
The space between + +
is to make the first one string concatenation and the second one a unary plus (ie "positive") operator.
(+ +
之间的空格是使第一个字符串串联,而第二个字符串成为一元加号(即“正”)运算符。)
You have the same result if you use 'ba'+(+'a')+'a'
, resolved as 'ba'+NaN+'a'
, which is equivalent to 'ba'+'NaN'+'a'
due to type juggling.(如果使用'ba'+(+'a')+'a'
,则得到相同的结果,解析为'ba'+NaN+'a'
,等效于'ba'+'NaN'+'a'
打杂耍。)
document.write('ba'+(+'a')+'a');
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…