> ## 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 Addition Assignment

The `+=` operator is a compound assignment operator that performs addition (or string concatenation) and assignment in a single operation. According to the Go specification, it evaluates the statement `x += y` as `x = x + (y)`, with the strict compiler guarantee that the left-hand operand `x` is evaluated exactly once. The implicit parentheses around the right-hand operand ensure that the order of operations is preserved, which is critical for operations lacking strict associativity, such as floating-point arithmetic.

```go theme={"dark"}
operand1 += operand2
```

## Mechanics and Type Constraints

Because Go is a statically and strictly typed language, the `+=` operator enforces rigid type safety rules during compilation:

1. **Type Equivalence:** `operand1` and `operand2` must be of the identical type. Go does not perform implicit type coercion between different numeric types (e.g., `int32` and `int64`).
2. **Untyped Constants:** If `operand2` is an untyped constant, it must be implicitly representable by the type of `operand1`.
3. **Statement, Not Expression:** In Go, assignment operations are statements, not expressions. You cannot assign the result of a `+=` operation to another variable or evaluate it inline (e.g., `z := (x += y)` is a syntax error).

## Supported Data Types

The operator exhibits polymorphic behavior depending on the underlying types of the operands:

* **Numeric Types:** Performs standard arithmetic addition. Supported types include all integer variants (signed and unsigned), floating-point numbers (`float32`, `float64`), and complex numbers (`complex64`, `complex128`).
* **Strings:** Performs string concatenation, appending the right operand to the end of the left operand and allocating a new underlying string in memory.

## Syntax Visualization

**Numeric Addition:**

```go theme={"dark"}
var count int = 10
count += 5 
// Evaluates as: count = count + (5)
// Result: 15
```

**Order of Operations Preservation:**

```go theme={"dark"}
var x float64 = 1.5
var a float64 = 2.0
var b float64 = 3.0

x += a + b
// Evaluates as: x = x + (a + b)
// The parentheses prevent mathematically different results in floating-point arithmetic.
```

**String Concatenation:**

```go theme={"dark"}
var prefix string = "sys_"
prefix += "admin" 
// Evaluates as: prefix = prefix + ("admin")
// Result: "sys_admin"
```

**Strict Typing Enforcement:**

```go theme={"dark"}
var a int32 = 10
var b int64 = 5

// a += b 
// Compiler Error: invalid operation: a += b (mismatched types int32 and int64)

a += int32(b) // Valid: Explicit type conversion satisfies type equivalence
```

## Single Evaluation Guarantee

When the left-hand operand contains an expression (such as a function call, pointer dereference, or map/slice index), Go guarantees that the expression is evaluated only once.

```go theme={"dark"}
// The function computeIndex() is called exactly once.
// If this were written as slice[computeIndex()] = slice[computeIndex()] + (1), 
// the function would be executed twice.
slice[computeIndex()] += 1
```

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