Using the JS `!` operator to toggle true ⇄ false settings


#1

Toggling between two alternative settings is often useful.

If the setting that you want to toggle has a boolean (ON ⇄ OFF) (true ⇄ false) value, then the JS ! operator (not or logical negation) is a very useful instrument, giving us:

!true -> false

and

!false -> true

For example, we can toggle link mode by writing:

editor.linkModeEnabled = !editor.linkModeEnabled

or toggle focus mode by writing:

editor.focusModeEnabled = !editor.focusModeEnabled

and toggle the flagged status of the active draft by writing:

draft.isFlagged = !draft.isFlagged