JavaScript has assignment operators corresponding to arithmetic ones: +=
, -=
, *=
, /=
, %=
.
JavaScript also has assignment operators corresponding to bitwise ones: <<=
, >>=
, >>>=
, &=
, ^=
, |=
.
But it doesn't have assignment operators corresponding to logical ones: ||=
, &&=
.
Then, I can't do things like
aVeryLongVariableIdontWantToRepeat ||= 1;
In this other question it's explained why JS Java doesn't have such operators. I guess it's the same for JS.
But I want to know if there is a simple way to emulate them, avoiding
aVeryLongVariableIdontWantToRepeat = aVeryLongVariableIdontWantToRepeat || 1;