3

for example in the indexOf polyfill in MDN

fromIndex = +fromIndex || 0;

What does the + in front of fromIndex do?

dazer
  • 223
  • 1
  • 4
  • 14
  • FWIW, the operator is [Unary Plus](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators) – user2864740 Jan 28 '14 at 01:37

1 Answers1

4

Converts it into a number. It's the opposite of -fromIndex, so it has to convert into a number.

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#-_.28Unary_Plus.29

+"0" 
>> 0
+true 
>> 1
Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217