Constant
A constant is a value or named binding treated as fixed rather than reassigned or modified during a computation, whether this is enforced by a language or followed by convention.
Modern C
A constant is a named C entity or value that does not change during program execution.
- How it is used
- Distinguishes read-only objects from named and compile-time constants while motivating meaningful names for repeated values.
- How deep it goes
- Explains qualification through arrays and strings, then defers the details of pointers and temporary objects.
- Examples
- Uses arrays of bird names, pronouns, and ordinals with repeated counts, and const-qualified pointers initialized to zero.
- What you can do after
- Evaluate whether a declaration provides a read-only view or a compile-time constant, and choose distinct names for values with different meanings.
Modern C, Third Edition
A const-qualified type is a C type whose referenced value is not modifiable through an expression having that type.
- How it is used
- Distinguishes read-only access from compile-time constants and flags const-qualification as a concern in text-processing interfaces.
- How deep it goes
- Explains qualified objects and pointer declarations through examples, while deferring detailed pointer mechanics.
- Examples
- Uses arrays of pointers to strings and contrasts an external const double declaration with a constexpr double.
- What you can do after
- Evaluate/understand whether a declaration gives read-only access or a compile-time constant guarantee.
Learn Rust in a Month of Lunches
- How it is used
- Provides compile-time, unchanging values, commonly for program-wide constants.
- How deep it goes
- Explains type annotations, compile-time evaluation, and global access, then develops the distinction from `static` later.
- Examples
- Uses NUMBER_OF_MONTHS, SEASONS, integer MIN and MAX values, and calculator input characters.
- What you can do after
- Build from scratch by declaring a typed compile-time value and accessing it from another function.
Read how Learn Rust in a Month of Lunches explains constant →
Practices of the Python Pro
- How it is used
- Centralizes repeated delimiters and reusable computed data so changes happen in one place.
- How deep it goes
- Demonstrates constants through short Python refactorings but stops short of discussing immutability or language-level enforcement.
- Examples
- Uses CSV-to-TSV delimiters and alphabetized United States state capitals as practical examples.
- What you can do after
- Apply it via named Python values to reduce duplicated edits and repeated calculations.
Kotlin in Action, 2E
The const modifier declares a compile-time constant property of a permitted primitive type or String type.
- How it is used
- Marks fixed top-level or object properties for compile-time use and direct Java field exposure.
- How deep it goes
- Defines placement, permitted types, initialization constraints, Java representation, and annotation usage without exploring compiler internals.
- Examples
- Uses UNIX_LINE_SEPARATOR for Java field exposure and TEST_TIMEOUT for a JUnit timeout annotation.
- What you can do after
- Apply const val to define Java-friendly constants and satisfy annotation arguments requiring compile-time values.
Secrets of the JavaScript Ninja, Second Edition
A 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.
- How it is used
- Uses const to prevent reassignment and name fixed values instead of unexplained literals.
- How deep it goes
- Explains initialization, reassignment errors, mutable object contents, and block scope while contrasting var and let.
- Examples
- Demonstrates reassignment failure with a string, object property addition, array mutation, and scoped loop variables.
- What you can do after
- Apply const to prevent binding reassignment and give fixed values meaningful names.
Read how Secrets of the JavaScript Ninja, Second Edition explains constant →
100 C++ Mistakes and How to Avoid Them
A constant is a named value that cannot be modified after it has been initialized.
- How it is used
- Marks named values and loop references as read-only, helping express constant data and prevent unintended modification.
- How deep it goes
- Shows constant declarations and read-only references, but does not detail const semantics beyond these uses.
- Examples
- Uses seconds per year, pi, degree conversion, and const references in container iteration.
- What you can do after
- Apply const to express read-only values and loop references in C++ code.
Read how 100 C++ Mistakes and How to Avoid Them explains constant →
Acing the Frontend Interview
const is a JavaScript block-scoped declaration form for bindings that must be initialized at declaration and cannot be reassigned.
- How it is used
- Frames const as an interview-relevant declaration choice for reasoning about scope, initialization, hoisting, and maintainability.
- How deep it goes
- Explains initialization, reassignment, block scope, and TDZ behavior, then connects them to scope tracing and closure examples.
- Examples
- Uses a closure counter to show a const binding alongside state that changes across repeated function calls.
- What you can do after
- Evaluate const declarations by tracing initialization timing, block scope, reassignment rules, and closure behavior.
Secrets of the JavaScript Ninja, Third Edition
const is a JavaScript keyword that declares a block-scoped binding that must be initialized and cannot be reassigned.
- How it is used
- Defines block-scoped bindings while supporting explanations of scope and execution order.
- How deep it goes
- Explains block scope and initialization-before-reference errors through execution examples.
- Examples
- Uses an early reference to x, a delayed function call, and nested blocks to demonstrate scope and initialization order.
- What you can do after
- Understand when a const binding is in scope and why referencing it before initialization throws a ReferenceError.
Read how Secrets of the JavaScript Ninja, Third Edition explains constant →
Rust in Action: Systems programming concepts and techniques
A const declaration defines a compile-time constant whose value cannot be changed.
- How it is used
- Distinguishes unchanging values from mutable global state in an example about error-code handling.
- How deep it goes
- Mentions const for values that never change but gives no const declaration example or deeper explanation.
- Examples
- Contrasts const with a mutable global ERROR variable used to propagate error information.
- What you can do after
- Understand that const denotes a value that never changes.
Read how Rust in Action: Systems programming concepts and techniques explains constant →
Systems Programming with Zig
A const variable is a binding whose value cannot be reassigned after declaration.
- How it is used
- Uses `const` to mark values that should not be reassigned and make mutability visible at declaration.
- 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.
Also covered in
- The Well-Grounded Rubyist, Fourth Edition
- Software Engineering for Data ScientistsIn early access (MEAP)
- Julia as a Second Language
- Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond
- Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu
- Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform
- Essential TypeScript 5, Third Edition
- JavaScript in DepthIn early access (MEAP)
- Go by Example
- Time Series Forecasting Using Foundation Models
- Pro Angular 16
What to know first
- functionA function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
- stringA string is a programming-language value representing textual data as an ordered sequence of characters or encoded units.
- ArcArc is Rust’s atomically reference-counted smart pointer, which enables shared ownership of a value across threads.
- compile timeCompile time is the phase before program execution in which source code is analyzed, checked, or transformed by language tools.
Related concepts
- 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.
Questions about constant
What is constant?
A constant is a value or named binding treated as fixed rather than reassigned or modified during a computation, whether this is enforced by a language or followed by convention.
Which Manning books explain constant?
Modern C, Modern C, Third Edition, Learn Rust in a Month of Lunches, Practices of the Python Pro, Kotlin in Action, 2E, Secrets of the JavaScript Ninja, Second Edition, 100 C++ Mistakes and How to Avoid Them, Acing the Frontend Interview and 3 more.
What should I know before learning constant?
Manning books that teach constant usually introduce function, string, Arc and compile time first.
What is the difference between constant and var?
A constant is a value or named binding treated as fixed rather than reassigned or modified during a computation, whether this is enforced by a language or followed by convention. 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.
What kinds of constant are there?
Kinds of constant include input and enum constant.
What is constant a kind of?
Constant is a kind of read-only object. A read-only object is an object that a program is not permitted to modify through its applicable access or type qualification.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.










