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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In your example
ewill be used if it is NOT a falsy value, such asfalse, 0, "", null, undefined. Otherwiseeventwill 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:
If the guard
value > 10evaluates totrueANDgetA()returns a falsy value, thengetB()will be returned. This is different from the if-then-else behavior, which would return the falsy result ofgetA().