What is the difference between
a *= 1;
and
a = +a;
in JavaScript?
Both convert a string
to number
(int or float). They behave differently from parseInt
and parseFloat
. But is there any difference between these two lines?
There isn't any difference. They are both converted to numbers using a ToNumber conversion. And the numerical multiplication by 1 and unary plus operation keep the values the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With