TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
== (equality) operator is a binary comparison operator that evaluates whether two operands are equal, yielding an untyped boolean value (true or false). For the operation to be valid, at least one operand must be assignable to the type of the other, and the types must be comparable according to Go’s type system. Go does not perform implicit type coercion during evaluation.
Comparability Rules by Type
The behavior and validity of the== operator depend entirely on the operand types:
- Basic Types (Booleans, Integers, Strings): Evaluated by value. Strings are equal if they have the same length and identical byte sequences.
- Floating-Point and Complex Numbers: Evaluated by value following IEEE-754 standard semantics. Notably,
NaN == NaNalways evaluates tofalse, and-0.0 == 0.0evaluates totrue. - Pointers: Evaluated by memory address. Two pointers are equal if they point to the same underlying variable or if both are
nil. Note: Pointers to distinct zero-size variables (e.g.,&struct{}{}) may or may not evaluate as equal depending on compiler optimizations and escape analysis. - Channels: Evaluated by reference. Two channel variables are equal if they were instantiated by the same
makeinvocation or if both arenil. - Structs: Evaluated by shallow field comparison. Two structs are equal if all corresponding fields (both exported and unexported) are equal. If a struct contains a pointer field,
==compares the memory address of the pointer, not the dereferenced value. A struct is only comparable if all of its constituent field types are comparable. - Arrays: Evaluated by element-wise comparison. Two arrays are equal if they have the same length and all corresponding elements are equal. Arrays are only comparable if their element type is comparable.
Interface Comparability and Runtime Panics
When applying== to interface values, Go compares both the dynamic type and the dynamic value. Two interface values are equal if:
- Both are
nil. - They possess identical dynamic types, and their underlying dynamic values are equal.
== operator is used on two interfaces that hold identical dynamic types, but that underlying type is strictly non-comparable (e.g., a slice), the compiler will allow the operation, but it will trigger a panic at runtime.
Non-Comparable Types
Slices, maps, and functions are strictly non-comparable. The Go compiler will reject any attempt to use the== operator to compare two variables of these types against each other.
The only permitted use of == with slices, maps, or functions is to compare them directly against the predeclared identifier nil.
Master Go with Deep Grasping Methodology!Learn More





