Reputation: 5
I have an boolean expression in javascript and i don't know what it means.
a = (b === LEFT && -2 || b === RIGHT && 2 || 0)
Please what does it mean ?
Upvotes: 0
Views: 55
Reputation: 546
one more shortcut with ternary operator
a = b === LEFT? -2: (b === RIGHT? 2 : 0)
Upvotes: 0
Reputation: 398
The && is a hacky shortcut if:
if (B === LEFT) {
a = -2;
} else if (B === RIGHT) {
a = 2;
} else {
a = 0;
}
Upvotes: 5