The use of || operator in assignments
- Dominant language
- JavaScript
- Stars
- 148k
- Forks
- 26.6k
- PR merge metrics
- No merged PRs in 30d
Description
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 if `a` is falsy so `b` 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.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with topic 15.7 and the examples using `const foo = a || b;`, then review how JavaScript treats falsy left operands. Determine whether the style guidance needs clarification or revision; the work is done when the guidance clearly addresses cases where `||` can produce an unintended value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100