In Contexts and contextualizers§

See primary documentation in context for Boolean.

This context will force a variable to be interpreted as True or False.

say "Hey" if 7;  # OUTPUT: «Hey␤»
say "Ahoy" if "";

This context appears in expressions such as if or while, and is equivalent to calling so on these values.

say "Hey" if 7.so;          # OUTPUT: «Hey␤»
say "Ahoy" if not set().so; # OUTPUT: «Ahoy␤»

In general, non-zero, non-empty will be converted to True; zero or empty will be equivalent to False. But .so can be defined to return any Boolean value we want, so this is just a rule of thumb.

The ? Boolean context operator and the ! negated Boolean context operator will force the Boolean context on an object.

say ? 0i;    # OUTPUT: «False␤»
say ! :true; # OUTPUT: «False␤»