What is immutability in Elixir?
Answer
In Elixir, all data is immutable — once a value is created, it cannot be modified. Operations on data return new values. For example: list = [1, 2, 3]; new_list = [0 | list] — list is still [1, 2, 3]; new_list is [0, 1, 2, 3]. Map update: map = %{a: 1}; new_map = %{map | a: 2} — map is unchanged. Immutability enables: Concurrency safety: no shared mutable state means no race conditions, no need for locks. Reasoning about code: a function's output depends only on its inputs — no hidden state changes. Efficient memory: the BEAM shares immutable data between processes structurally — no copying unless needed. Variable rebinding (x = x + 1) creates a new binding, not mutation. This is why Elixir code is inherently thread-safe without synchronization primitives for most patterns.