Reputation: 3907
I'm wondering if JavaScript allows multiple addition-assignment operators in one statement. I know about multiple variable assignment, discussed here.
My current way of coding looks somewhat like this:
var x = someComplicatedFunction();
foo += x;
bar += x;
Is there a way to do something like this?
foo, bar += someComplicatedFunction();
Upvotes: 2
Views: 736
Reputation: 382304
You can put as many statements as you want in one line :
var x = someComplicatedFunction(); foo += x; bar += x;
If you want to do everything in one statement, it's more messy but it's doable :
bar -= foo - (foo += someComplicatedFunction());
But there's nothing magical letting you do everything in one statement without assignation and being readable.
Upvotes: 2