Declare, infer, reassign
#let is immutable by default; mut allows assignment. A later let may shadow a name. const also requires a type and a constant expression.
Fragment
Fragment inside a function.
Reference
Choose TypeScript, Go, Rust or C++ and find syntax, everyday APIs, standard libraries and tools in one place.
TypeScript/Node, Go 1.23+, Rust 2024 and C++23: from a first CLI to files, JSON, HTTP, concurrency and testing. Complete programs are labeled; other examples identify their surrounding code/imports. Optional libraries and version requirements are named in each entry.
Rust docs Variables and mutability ↗
let is immutable by default; mut allows assignment. A later let may shadow a name. const also requires a type and a constant expression.
Fragment
Fragment inside a function.
let introduces a binding and can shadow a name in an inner block or the same scope, even with a different type. Reassigning an initialized binding requires mut and keeps its type. After an inner block, the outer binding is visible again.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
Rust requires initialization before a value is read. Default is a trait convention, not an automatic zeroing rule for every type. derive(Default) works when every field supports it.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
== uses PartialEq, often derived for custom records. Collections can compare element values. Pointer identity is a separate question; == on references ordinarily compares the referred-to values.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
Copy types duplicate implicitly. Assigning a non-Copy owned value usually moves it, making the old binding unusable. clone explicitly requests duplication according to the type’s Clone implementation; shared handles may still share data.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.