Converting a string to a number with a plus sign is a hack and is therefore one of the things you shouldn't do in JavaScript (just like changing the length property of an array).
Hi Nikola, thanks for reading. Yes, these two are tricks definitely. But, I saw both on MDN docs and w3docs, so I would consider them a legit tricks. :)
What about explicit conversion from string to number: str => Number(str)? I think this one is clearer and easier to understand/note for other developers.
Converting a string to a number with a plus sign is a hack and is therefore one of the things you shouldn't do in JavaScript (just like changing the length property of an array).
Hi Nikola, thanks for reading. Yes, these two are tricks definitely. But, I saw both on MDN docs and w3docs, so I would consider them a legit tricks. :)
How do you like the rest?
What about explicit conversion from string to number: str => Number(str)? I think this one is clearer and easier to understand/note for other developers.
parseInt(str, 10)
Hi Olga. Hi Antonio.
Thanks for reading and taking the time to comment.
There is at least 10 different ways to convert a string to number. Maybe I create a dedicated post about this topic.