0

Based on this question How does “+var === +var” work internally to verify if var is numeric? :

var a = "123"
var b = "123b"
if ( +a === +a ) // true
if ( +b === +b ) // false

my question is how if javascript can't convert "123b" to a number, the Value would be NaN so how is typeof +b // Returns number`

How does this logic work.

Community
  • 1
  • 1
Ale_
  • 85
  • 7
  • NaN is not a number and also not a value at all. Hence it can't be equal to anything. The type of +b EXPRESSION is number because the plus sign forces the coercion to that type. Even it's holding VALUE is actually not a (valid) number. – bitifet May 18 '15 at 15:36
  • @bitifet: You might have already read the duplicate question, but for others just passing by here and reading this comment: `NaN` actually **is** a number value. That's why `typeof NaN` returns `"number"`. It's not equal to anything, because that's what the IEEE 754 standard dictates and what JS implements: http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.3 – Felix Kling May 18 '15 at 15:58
  • according to ECMAScript http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.6, given `x === y`, part 4.a.,b.: if `x` or `y` is `NaN`, return `false`. – Claies May 18 '15 at 16:01

0 Answers0