-
Notifications
You must be signed in to change notification settings - Fork 26.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The use of || operator in assignments #990
Comments
In the comparison, In the general case, |
True, but the ternaries has the advantage of the comparison right? So you could do |
Sure, but that's not what 15.7 is addressing. In that case, it'd be fine to use a ternary. |
Got you. So, I just created the issue because I already faced one or two bugs because of this pattern of using |
Yes, if you want to add a new section that in general discourages using |
Actually, it seems 7.7 already explains that in the comments of the example. Maybe the content of the comment presented as a |
Just FYI: technically the |
That is true - and even more of a reason why |
In the topic 15.7 this kind of assignment is favored over ternaries:
const foo = a || b;
. Actually, this pattern is used in a lot of the examples, but should it be discouraged since it can produce undesired behavior when the left operand is falsy? In the above example ifa
is falsy sob
would be the result.I know the developer should distinguish problematic cases, but one of the goals of the style guide is to avoid potential issues.
The text was updated successfully, but these errors were encountered: