not
Returns the boolean negation of its single argument.
- Syntax
- not VALUE
- Returns
- bool
Usage
The not function returns the boolean negation of its single argument. Unlike the and and or functions, the not function always returns a boolean value.
The falsy values are false, 0, any nil pointer or interface value, any array, slice, map, or string of length zero, and zero time.Time values.
Everything else is truthy.
See Go’s text/template documentation for more information.
Examples
{{ not true }} → false
{{ not false }} → true
{{ not 1 }} → false
{{ not 0 }} → true
{{ not "x" }} → false
{{ not "" }} → trueCasting any value to a boolean value by calling the function twice:
{{ 42 | not | not }} → true
{{ "" | not | not }} → falseLast updated:
November 23, 2026
:
content: Apply style guide to go-template functions (f834b61d1)
Improve this page