To sum up another answer, a comment and my own opinion, I suggest combining two things:
- Use a function for the toggle
- Inside this function use a more readable implementation
Here is the function which you could place in a library or maybe wrap it in a Plugin for another Javascript Framework.
function inv(i) {
if (i == 0) {
return 1
} else {
return 0;
}
}
And the usage is simply:
v = inv(v);
The advantages are:
- No code Duplication
- If you or anybody read this again in the future, you will understand your code in a minimum of time.