My rule of thumb, which covers basically 99% of all use cases for conditional statements, is:
- Grouping:
() - Member access
. or [...] - Not:
! - Comparison, e.g.
< , >= , === , !=, ... - Logical AND
&& - Logical OR
||
MDN gives you the exhaustive breakdown: JavaScript Operator Precedence
So for your example:
(firstRun == true || selectedCategory != undefined && selectedState != undefined)
equals
(firstRun == true) || ((selectedCategory != undefined) && (selectedState != undefined))
For anything more complex than the above mentioned cases, I would look into refactoring the code for readability’s sake anyway!