Logical or instead of ternary

javascript, logical-operators, ternary-operator

Solution

In your example `e` will be used if it is NOT a falsy value, such as `false, 0, "", null, undefined`. Otherwise `event` will be used. In your case this should be save.

But there is some danger in using more complex logical expressions instead of if-then-else (or ternary). Here is an example:

result = value > 10 && getA() || getB()

If the guard `value > 10` evaluates to `true` AND `getA()` returns a falsy value, then `getB()` will be returned. This is different from the if-then-else behavior, which would return the falsy result of `getA()`.

Problem

I've a legacy script. This is a part from it: ``` var e = e ? e : event; ``` So, nothing wrong here. But I use ternary mainly for toogling. Can it safely be rewritten like this ``` var e = e || event; ``` Is there any hidden reason for not using this one?

Original source