Part 0 · 1 chapters · ~8 min

Values and Types

Values, variables and bindings, value versus reference semantics, equality versus identity, mutability and immutability, primitive representations (integers, overflow, IEEE 754 floats, decimals), strings and encodings, and what a type is: a set of values plus the operations allowed on them.

1

The same line, different languages

code
// JavaScript: objects are shared references
const a = { balance: 100 }; const b = a; b.balance = 0; a.balance   // 0

// Go: structs are copied on assignment
a := Account{Balance: 100}; b := a; b.Balance = 0; // a.Balance is still 100

// Rust: assignment moves ownership; a is no longer usable
let a = Account { balance: 100 }; let b = a; // println!("{}", a.balance) → compile error: value moved

// Python: ints are immutable objects, lists are mutable and shared
xs = [1, 2]; ys = xs; ys.append(3); xs   # [1, 2, 3]

0.1 + 0.2 === 0.3                 // false: binary floating point (IEEE 754)
2 ** 53 + 1 === 2 ** 53           // true: integers above 2^53 lose precision in JS numbers → use BigInt

A type is a set of values with operations. int64 is about 1.8 × 10¹⁹ values with arithmetic that wraps or traps on overflow depending on the language: Go and Java wrap silently, Rust panics in debug builds and wraps in release unless you use checked_add, Python integers grow without limit.

VALUES, REFERENCES AND IDENTITY
what a variable actually holds
value semanticsAssignment copies: Go structs,Rust (by move or Copy), C structs.reference semanticsAssignment shares an object: JSobjects, Python, Java objects.equality vs identity== on content vs the same object:=== on objects, Python is.mutabilityCan the value change aftercreation? const binding ≠immutable value.numbersInts overflow or grow; floats arebinary: 0.1 + 0.2 ≠ 0.3.stringsBytes, UTF-16 code units or codepoints, depending on the language.
swipe the figure sideways, or tap expand for full screen
1/4
copy or share
In Go, assigning a struct copies it; in JavaScript, assigning an object shares it. The same line of code means different things.
copy vs sharesame syntax, different meaning