Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a *= 1 and a = +a?

Tags:

javascript

int

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?

like image 341
Ismat Valiev Avatar asked Mar 10 '18 09:03

Ismat Valiev


1 Answers

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.

like image 172
fgb Avatar answered Sep 28 '22 19:09

fgb