Scenario
A feature should show only when the user is active and either owns the record or has admin access. The pull request contains active && owner || admin — compact, plausible, and wrong in a way that only shows up for inactive admins. In JavaScript and most C-family languages && binds tighter than ||, so this parses as (active && owner) || admin, which lets an inactive admin through. Operator precedence bugs survive code review because everyone reads the intent, not the parse.
Broken input
active && owner || admin
Goal
Use Truth Table Generator to enumerate every boolean combination before approving the condition. Eight rows take seconds to read; a production incident about an inactive admin seeing the feature takes considerably longer.
Tool sequence
- Open Truth Table Generator.
- Enter
active && owner || adminexactly as written in the PR — the generator applies real operator precedence, which is the thing under test. - Scan the rows where the result is true and look for
active = falsecombinations. - The row
active=F, owner=F, admin=T → trueis the bug: admin bypasses the active check. - Enter the corrected
active && (owner || admin)and confirm every true row now hasactive = T, then paste both tables into the PR review.
Checkpoint output
active owner admin | active && owner || admin | active && (owner || admin)
F F T | true ← bug | false
T F T | true | true
T T F | true | true
The unparenthesized expression is true for an inactive admin; the parenthesized version gates everything behind active as intended.
Common mistakes
- Trusting natural-language intent ("active and owner or admin") instead of checking how
&&/||precedence actually parses it. - Testing only the happy path and one failure path — the bug lives in row 2 of 8, not row 1 or 8.
- Changing parentheses without re-generating the full table to confirm nothing else flipped.
- Assuming the linter would catch it — most linters only warn on mixed
&&/||without parentheses if that rule is enabled.
Related tools and lessons
- Bitwise Operations Calculator - Evaluate AND, OR, XOR, NOT, and bit shifts by width.
- Regex Tester - Test regex patterns with live highlighting.
- JSON Schema Validator / Generator - Validate JSON with Draft 2020-12 or generate starter schemas.
- Related lesson: Debug a Bitmask Permission Check
- Related lesson: Build a Regex That Catches the Right Inputs