Sometimes we want to convert a number to a string; in my latest code piece, there was a limit set on a data attribute. This comes true as a string,...
For further actions, you may consider blocking this person and/or reporting abuse
+'1'
Keep in mind that this also works for hexadecimal.
And so does
~~
I Actually didn't know about the ~~ What is it called?
it's the NOT bitwise operator. It changes the 1 by 0 and 0 by 1. In that example, he is doing it twice.
~ 5 => ~0101 => 1010
~~5 => ~(~0101) => ~(1010) => 0101 => 5
w3schools.com/js/js_operators.asp
😂👏
I do realize all methods, but never notice that
parseFloat
trims, butNumber
returnNaN
.Yes, Number is very strict the string can only contain actual numbers!
Worth knowing that this depends on the user's browser locale. 13,37 is a valid number in French and German, whereas 13.37 is not.
You are right, there is the option to use locales on strings and numbers before. but your right good to keep this in mind!
Keep posting daily tips, i love to read and learning it
I use parsefloat to parsing bitcoin balance from rpc in my current project
Awesome, thanks man! Glad people find them amazing 🤟
~~’1’
I just saw above, actually didn't know that option 🤯