A const variable is a binding whose value cannot be reassigned after declaration.
In Zig, `const` declares a variable that cannot be reassigned to a new value. Choose it when the value should not change; use `var` only when it should. section 1.3.1
Zig enforces the choice:
Changing a `const` value is an error; declaring a `var` that never changes is also an error. section 1.3.1
The declaration makes mutability visible where the variable is introduced, helping readers understand and debug code. section 1.3.1
How Systems Programming with Zig covers it
How deep it goes
Defines reassignment rules and compiler checks, then notes readability and performance benefits without a worked code example.
What you can do after
Evaluate whether a variable should be reassigned and declare it as `const` or `var` accordingly.
How it connects
Connects const variables to `var`, mutability, compiler checks, and code readability.
Secrets of the JavaScript Ninja, Second EditionA JavaScript binding declared with const that must be initialized at declaration and cannot be reassigned, although an object or array it references can still be modified.
Acing the Frontend Interviewconst is a JavaScript block-scoped declaration form for bindings that must be initialized at declaration and cannot be reassigned.
varcontrasts with · var is a JavaScript keyword that declares a function-scoped variable, or a global-scoped variable at the top level, with a binding that can be reassigned.
factoryused by · A factory is a function, method, or component that creates and returns values or objects while encapsulating construction or selection logic.
inputincludes · An input is information, a value, or an action supplied to a system, program, or computation for processing or to influence its behavior.
enum constantincludes · An enumeration constant is a named member of an enumeration representing one distinct enumerated value.
let keywordcontrasts with · A let construct is a language feature that introduces a name binding associating an identifier with a value or expression.
read-only objectkind of · A read-only object is an object that a program is not permitted to modify through its applicable access or type qualification.
This explainer was generated by Manning's knowledge graph from the text of Systems Programming with Zig. The section links point to the parts of the book it draws on.