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

The `!=` (inequality) operator is a binary comparison operator that evaluates whether two operands are not equal. It returns an untyped boolean value: `true` if the operands differ in value, and `false` if they are identical.

```go theme={"dark"}
var operand1, operand2 int
_ = operand1 != operand2
```

Because Go is statically and strictly typed, the `!=` operator does not perform implicit type coercion. For the expression to compile, the operands must satisfy two strict language mechanics: **assignability** and **comparability**.

## Assignability

`operand1` must be assignable to the type of `operand2`, or vice versa. You cannot directly compare an `int` to a `float64` without an explicit type conversion.

```go theme={"dark"}
var a int = 5
var b float64 = 5.0

// Invalid: mismatched types int and float64
// _ = a != b 

// Valid: explicit type conversion
_ = float64(a) != b 
```

## Comparability Rules

The Go language specification defines exactly which types are *comparable*. The `!=` operator behaves differently depending on the underlying types being evaluated:

* **Basic Types (Booleans, Numerics, Strings):** Evaluates to `true` if the underlying scalar values differ. Floating-point inequality adheres to IEEE-754 standards (e.g., `NaN != NaN` is always `true`).
* **Pointers:** Evaluates to `true` if the pointers hold different memory addresses, or if one is `nil` and the other is not.
* **Channels:** Evaluates to `true` if the channel references point to different underlying data structures (created by different `make` calls), or if one is `nil` and the other is not.
* **Interfaces:** Evaluates to `true` if the two interface values have different dynamic types, or if they have the same *comparable* dynamic type and their underlying dynamic values are not equal. **Critical behavior:** If the interfaces share the same dynamic type but that dynamic type is non-comparable (e.g., a slice, map, or function), the `!=` operation will trigger a **run-time panic**.
* **Structs:** Evaluates to `true` if any corresponding non-blank fields between the two structs are not equal. Blank fields (`_`) are explicitly ignored during the evaluation of equality. However, a struct is only comparable at compile-time if **all** of its fields—including blank fields—are of comparable types. If a struct contains a blank field of a non-comparable type, the entire struct becomes non-comparable. If a struct contains interface fields, the comparison cascades and is subject to the same run-time panic risk if the interface holds a non-comparable dynamic type.
* **Arrays:** Evaluates to `true` if any corresponding elements at the same index differ. Arrays are only comparable if their element type is comparable. Like structs, arrays of interfaces can trigger a run-time panic during comparison.

```go theme={"dark"}
// Struct comparison mechanics
type Point struct { 
    X, Y int 
    _    int // Blank fields are ignored during evaluation, but MUST be of a comparable type
}
p1 := Point{X: 1, Y: 2}
p2 := Point{X: 1, Y: 3}
_ = p1 != p2 // true, because the Y fields differ

type InvalidPoint struct {
    X int
    _ []int // Non-comparable type makes the entire struct non-comparable
}
// var ip1, ip2 InvalidPoint
// _ = ip1 != ip2 // Compile-time error: InvalidPoint is not comparable

// Interface run-time panic mechanics
var i1 interface{} = []int{1, 2}
var i2 interface{} = []int{1, 2}
// Compiles successfully, but crashes at runtime:
// panic: runtime error: comparing uncomparable type []int
// _ = i1 != i2 
```

## Non-Comparable Types

Slices, maps, and functions are explicitly **non-comparable** in Go. You cannot use the `!=` operator to compare two slices, two maps, or two functions against each other directly. Attempting to do so results in a compile-time error.

The only valid use of the `!=` operator with slices, maps, or functions is to compare them against the predeclared identifier `nil`.

```go theme={"dark"}
slice1 := []int{1, 2, 3}

// ERROR: invalid operation: slice1 != slice2 (slice can only be compared to nil)
// slice2 := []int{1, 2, 3}
// _ = slice1 != slice2 

// Valid: checking against nil
_ = slice1 != nil // true
```

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