Val

Keyword · Development

Definitions

  1. A keyword in Kotlin, Scala, and Swift that declares an immutable variable binding — once assigned, it cannot be reassigned. The counterpart of var (mutable). Prefer val by default for safer, more predictable code.

    In plain English: A way to declare a variable that can't be changed after it's set, encouraging you to write code that's easier to reason about.

    Example: "Use val unless you have a specific reason to mutate. Immutability by default prevents entire classes of bugs."

Related Terms