Photo by Mika Baumeister on Unsplash
Another ✔||🤢, casting to number with +;
Actually found this one in the angular documentation at some point.
// example: numberInputField.value = "3"
const startValue: number = +numberInputField.value;
casting to number with + ✔||🤢
❤: Commit (something I could commit)
🏷: Vomit (I'd never commit this)
🦄: I like your post please continue this series!
Let's vote! 😊
Discussion (10)
Oh boy, I'm not familiar with this one but I can say with great certainty that:
one more gif...
...

🤣🤣
I'll start myself. Came across something like this in the Angular docs, didn't like it because it is too easy mis, so Vomit. 🤢
it is a yuck for me, perhaps something more readable
same
Yuck. This is something I would've done everywhere as a junior dev having just found about it 🤦 Not at all obvious and more likely someone would see this and assume it was a mistake and remove it
Make it explicit and also tell us what to do if the type doesn't match
ALWAYS use Number.parseInt and add the radix or you may end up in an undetermined state. developer.mozilla.org/en-US/docs/W...
It's unorthodox, but it's a much better way to convert something into a number.