2

If you execute the following statement

"Test a b " + "c"
// Output
// "Test a b c"

but if you execute the following it treats "c" as a number.

"Test a b " + + "c"
// Output
// "Test a b NaN"

Why does two consecutive + signs treat the string as a number?

Tested in chrome 40.0.2214.111 m

Ally
  • 4,586
  • 7
  • 34
  • 42

1 Answers1

8

When you do "Test a b " + + "c", it is doing ("Test a b ") + (+ "c"), the first + is the string concatenation operator and the second + is the unary + operator, which converts to a Number

Paul S.
  • 61,621
  • 8
  • 116
  • 132
  • Interesting, thanks. I've learnt something new, I can use the unary + operator to cast to a number. – Ally Feb 19 '15 at 02:27