> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Go Equality

The `==` (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.

```go theme={"dark"}
result := operand1 == operand2
```

## 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 == NaN` always evaluates to `false`, and `-0.0 == 0.0` evaluates to `true`.
* **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 `make` invocation or if both are `nil`.
* **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.

```go theme={"dark"}
// Struct and Array comparison syntax
type Node struct { 
    Value int
    Next  *Node 
}

// Shallow comparison: n1 and n2 are equal only if they point to the exact same Next address
n1 := Node{Value: 1, Next: &Node{}}
n2 := Node{Value: 1, Next: &Node{}}
isEqual := n1 == n2 // false (different pointer addresses for Next)

arr1, arr2 := [3]int{1, 2, 3}, [3]int{1, 2, 3}
isEqualArr := arr1 == arr2 // true
```

## 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:

1. Both are `nil`.
2. They possess identical dynamic types, and their underlying dynamic values are equal.

If the `==` 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**.

```go theme={"dark"}
var i1 interface{} = []int{1, 2}
var i2 interface{} = []int{1, 2}

// Compiles successfully, but panics at runtime: 
// panic: runtime error: comparing uncomparable type []int
result := i1 == i2 
```

## 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`.

```go theme={"dark"}
var s []int
// Valid: Comparing to nil
isNull := s == nil 

s2 := []int{}
// Invalid: Compiler error (invalid operation: s == s2 (slice can only be compared to nil))
// isMatch := s == s2 
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Go Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
