Programming Languages - Constants and Variables
By Language
C++
Check const vs constexpr
Kotlin
constis for compile-time constants (e.g. creating constant strings similar tofinal staticin Java), this is similar toconstexprin C++;valis for read-only variables (similar tofinalin Java), and can be assigned at runtime; similar toconstin C++varis for mutable variables.
JavaScript
JavaScript also has const but it simply means "cannot be reassigned", it may NOT be a constant and it may NOT be immutable
const a = [1, 2];
a.push(3); // this is OK, a will be [1, 2, 3]
To achieve immutablility, use Object.freeze:
Object.freeze(a);
a.push(4);
// Uncaught TypeError: Cannot add property 4, object is not extensible
JavaScript:
const, var, let
Go
const, var