且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Javascript字符串赋值运算符

更新时间:2022-12-03 15:13:40

简短的回答是 - 它没有被定义为使用字符串。

The short answer is - it isn't defined to work with strings.

更长的答案:如果你在两个字符串上尝试减法运算符,它将首先将它们转换为数字,然后执行算术运算。

Longer answer: if you try the subtraction operator on two strings, it will first cast them to numbers and then perform the arithmetic.

"10" - "2" = 8

如果您尝试非数字化的东西,则会收到与NaN相关的错误:

If you try something that is non-numeric, you get a NaN related error:

"AA" - "A" = NaN