Is there any difference in using the + operator to press?

I compared two branches, and there is a discrepancy in the code, and + operator , in my opinion it does not matter , since it clicks.
Is there any difference?

Front

 if (numberPattern.test(val)) { var getNumbers = val.match(numberPattern); for (i = 0; i < getNumbers.length; i++) { valores.push(getNumbers[i]) } } 

After

 if (numberPattern.test(val)) { var getNumbers = val.match(numberPattern); for (i = 0; i < getNumbers.length; i++) { valores.push(+getNumbers[i]) } } 
+5
source share
2 answers

It converts it to Number , where another case leaves it as a string.

+7
source

+ will actually change getNumbers[i] to type number . + (unary operator) is actually used to convert it to number .

Try running this code:

 var s = "1"; //String var s1 = +s; //String changed to a number now console.log(typeof s1); 

You will see that type s1 will be number .

+2
source

All Articles