javascript - 为什么 "string"- "string"是 NaN?

标签 javascript nan typeof

<分区>

这对我来说就像一个无限循环。

var sM = "Hello" - "World";
console.log(sM) && console.log(typeof sM);

我理解为什么 string - string 输出 NaN,但是 "Hello"- "World" typeof 是一个 number

这意味着用另一个字符串减去一个字符串得到一个数字的类型。

这其中的逻辑在哪里?

最佳答案

why string - string outputs NaN

因为减法只处理数字,所以它将两边都转换为数字并得到不是数字

but then "Hello" - "World" typeof is a number.

NaN 的类型是NumberThis is standard in computing .

关于javascript - 为什么 "string"- "string"是 NaN?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37301296/

相关文章:

Javascript 随机数生成器出现 NaN

python - NaN 作为字典中的键

c - Sun Studio 编译器 : implicit function declaration: typeof

javascript - 为什么使用 ('function' === typeof x) 而不是 (typeof x === 'function' )

javascript - 有没有办法在开始执行 javascript 之前转换由 HtmlUnit 加载的页面?

python - 如何合并 Pandas 中的两个数据框以替换nan

javascript - Fancybox 2.0 无法运行,非常简单的第一次测试

javascript - 为什么 typeof array[0] == 'undefined' 不起作用?

javascript - 如何处理 Protractor 中的 UnexpectedAlertOpenError

javascript - 单个等号在javascript中的if语句中如何工作