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

A constant in Go is an immutable, compile-time construct representing a fixed value. Declared using the `const` keyword, constants are evaluated by the compiler rather than at runtime. They are strictly limited to boolean, rune, integer, floating-point, complex, and string types.

## Syntax

Constants can be declared individually or grouped within a block.

```go theme={"dark"}
// Single declaration
const Pi float64 = 3.14159265359

// Grouped declaration
const (
    StatusOK       = 200
    StatusNotFound = 404
)
```

## Typed vs. Untyped Constants

Go distinguishes between typed and untyped constants, a mechanism that provides flexibility within its strict type system.

**Untyped Constants**
An untyped constant possesses a value and a *default type* (e.g., `int` for `42`, `float64` for `3.14`), but it is not strictly bound to that type. Numeric untyped constants exist in an arbitrary-precision mathematical space. They do not overflow and can be implicitly converted to any compatible type upon assignment.

```go theme={"dark"}
const MaxUint64 = 18446744073709551615 // Untyped integer, arbitrary precision
const Huge = 1e1000                    // Valid at compile time, despite exceeding float64 bounds
```

**Typed Constants**
A typed constant is explicitly bound to a specific Go type. Once typed, the constant loses its arbitrary precision and is subject to the memory bounds and overflow rules of its underlying type.

```go theme={"dark"}
const TypedInt int8 = 127
// const Overflow int8 = 128 // Compiler error: constant 128 overflows int8
```

## Constant Expressions

Expressions consisting entirely of constants are evaluated at compile time. The result of a constant expression is itself a constant. If the operands are untyped, the result remains untyped, maintaining arbitrary precision during intermediate calculations.

```go theme={"dark"}
const A = 10
const B = 20
const C = A * B / 5 // Evaluated entirely at compile time
```

## The `iota` Identifier

`iota` is a predeclared identifier used exclusively within `const` declarations to generate sequences of numbers. It represents successive untyped integer constants. `iota` is reset to `0` whenever the reserved word `const` appears in the source code and increments by `1` after each ConstSpec (constant specification) within a block.

```go theme={"dark"}
const (
    Zero = iota // 0
    One         // 1 (Implicitly uses iota)
    Two         // 2 (Implicitly uses iota)
)
```

`iota` can be combined with constant expressions to generate complex compile-time sequences, such as bitwise shifts.

```go theme={"dark"}
const (
    ShiftA = 1 << iota // 1 << 0 = 1
    ShiftB             // 1 << 1 = 2
    ShiftC             // 1 << 2 = 4
)
```

## Implicit Repetition

In a grouped constant declaration, if the expression list is omitted, the compiler implicitly repeats the preceding expression and its type.

```go theme={"dark"}
const (
    X = 10.5 // Untyped float
    Y        // 10.5
    Z        // 10.5
)
```

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