为什么 isNaN('-10') 是假的?
Why is isNaN('-10') false?
只是好奇为什么 isNaN('-10')
是假的?我在想 isNaN('-10')
应该是真的,但是 isNaN(-10)
应该是假的?
Javascript 是否尝试在应用 isNaN
之前将字符串转换为数字?
来自MDN:
Since the very earliest versions of the isNaN function specification, its behavior for non-numeric arguments has been confusing. When the argument to the isNaN function is not of type Number, the value is first coerced to a Number. The resulting value is then tested to determine whether it is NaN.
isNaN
隐式转换为 Number 类型。 Link
只是好奇为什么 isNaN('-10')
是假的?我在想 isNaN('-10')
应该是真的,但是 isNaN(-10)
应该是假的?
Javascript 是否尝试在应用 isNaN
之前将字符串转换为数字?
来自MDN:
Since the very earliest versions of the isNaN function specification, its behavior for non-numeric arguments has been confusing. When the argument to the isNaN function is not of type Number, the value is first coerced to a Number. The resulting value is then tested to determine whether it is NaN.
isNaN
隐式转换为 Number 类型。 Link