There’s something innately more difficult about thinking “not this” as opposed to “this”. You want to keep an eye out for doubling and even tripling up the negations.

Three ways people typically express negation:

  • The not symbol, which is usually an exclamation !
  • The else keyword or symbol (including in ternary operations)
  • The variable name: (e.g. notStopped)

Each on their own is fine. The real issue shows up when you have two or more combined. If you catch this in your code, you can clean it up with these two steps:

  • Rename the variables to their positive state

    e.g. notStopped becomes isStopped

  • If you have an else combined with a not, remove the not and swap the internal brackets:

    if (!gameOver) { A } else { B }

    becomes

    if (gameOver) { B } else { A }