Say I have a string, which value is already a number, e.g. var str = "1234"
Now I want to convert it to number.
I have seen two tricks on the internet so far,
- Use the unary
+
:var num = +str
- Use the multiply operator
*
:var num = str*1
I want to know which one is better in general.
As I saw from the comment of the accepted answer here: Converting Json Results to a Date, it seems like *1
is best to be avoided. Is this true and what is the reason behind it?