Declare, infer, reassign
#const prevents rebinding; let allows it. A type follows the name, or is inferred. Neither makes an object deeply immutable.
Fragment
Fragment inside a function or module.
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.
TypeScript docs Everyday types ↗
const prevents rebinding; let allows it. A type follows the name, or is inferred. Neither makes an object deeply immutable.
Fragment
Fragment inside a function or module.
let/const are block-scoped. An inner declaration can hide an outer name; assigning without a declaration updates the binding found in that scope. var is function-scoped instead. The inner count below does not replace the outer binding.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
An uninitialized JavaScript let value is undefined. TypeScript’s definite-assignment checks can reject reading a typed variable before assignment. Type annotations do not manufacture a zero/default value.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
=== compares primitives by value and objects by identity. Equal-looking object literals are different objects. Object.is differs for NaN and signed zero. Neither performs a recursive deep object comparison.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.
Assigning an object/array shares the same object. Spread creates a shallow copy: nested objects can remain shared. structuredClone supports deeper copies of supported values, but is not a universal clone of arbitrary objects.
Fragment
Fragment: imports and type/function declarations at file scope; usage statements inside a function.