JavaScript Runtime Semantics
Values, Types & Primitives
JavaScript values are either primitives or objects. Primitives are immutable values; objects are mutable identity-bearing containers. Variables are bindings that point at values, not boxes that contain them.
- The runtime has values, not TypeScript types
- Primitives are immutable values
- Objects have identity and can be mutated through references
constfreezes the binding, not the object- Arrays and functions are objects too
| Category | Examples | Key behavior |
|---|---|---|
| Primitive | string, number, boolean, bigint, symbol, null, undefined | Immutable value |
| Object | plain object, array, function, Date, Map, Set | Mutable identity |
| Binding | let/const/var name | Points at a value |
| Reference | A way to reach an object | Multiple references can reach same object |
const a = "hello"
const b = a.toUpperCase()
console.log(a) // "hello"
console.log(b) // "HELLO"
const user = { name: "Ana" }
const sameUser = user
sameUser.name = "Mila"
console.log(user.name) // "Mila"