DEV Community

Cover image for " ! " Not Operator
GiandoDev
GiandoDev

Posted on

" ! " Not Operator

The not operator avoid us from writing the else statemet like in this example:
Alt Text
In the example above we ask with our if(!apples) : if apples is falsey run this argument, so we avoid to write this:
Alt Text
Another occasion where it can be very useful is when we need to convert a Truthy and Falsey values in True and False.
Alt Text
In the example above we convert first apples(falsey) into apples(true) with our first not operator(!), with the second not operator we convert our apples(true) in apples(false), then our apples(falsey) has become apples(false). The opposite happened for our apples(truthy).

Top comments (0)