Declare, infer, reassign
#:= declares inside a function, inferring types; at least one name must be new in that block. = assigns. const names a constant.
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.
:= declares inside a function, inferring types; at least one name must be new in that block. = assigns. const names a constant.
Fragment
Fragment inside a function.
:= in an inner block declares a new binding and can shadow an outer name; = assigns an existing binding. In the same block, := may reuse names only when at least one non-blank name is new. The inner count below leaves the outer count unchanged.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
var without an initializer supplies the type’s zero value: numeric 0, false, empty string or nil for nil-capable types. Structs and arrays recursively zero their fields/elements.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
Comparable arrays/structs compare their components. Slices/maps generally cannot use == except against nil. slices.Equal compares slice elements; pointer equality compares addresses.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
Arrays and structs are copied as values. A copied slice still refers to backing storage; copied maps refer to the same map. A struct containing slices/maps therefore need not be an independent deep copy.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.