It's not actually a toggle, it's a check that the value is a boolean.
Read it from the inside out.
Inner parenthesis asks if something is false. If it is the value of the expression is true (false does equal false). Take the negative of that (! true
) which returns the boolean value false
.
If something is true, the inner expression is false, true != false
. Take the negative of that (! false
) and the result is true
.
OK, so what if something is undefined? Undefined will evaluate as false and since false === false the expression is true. Negating that (! true
) returns false
.
So anything that is true is returned as true and undefined or false values always return false.