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
  • const freezes the binding, not the object
  • Arrays and functions are objects too
Runtime categories
CategoryExamplesKey behavior
Primitivestring, number, boolean, bigint, symbol, null, undefinedImmutable value
Objectplain object, array, function, Date, Map, SetMutable identity
Bindinglet/const/var namePoints at a value
ReferenceA way to reach an objectMultiple references can reach same object
Primitive value vs object identity
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"
String operations create new primitive values; object mutation changes the referenced object.
Sources
  • MDN JavaScript Guide and ReferenceGrammar and types
  • ECMAScript Language SpecificationECMAScript data types and values
  • Eloquent JavaScript, 4th EditionValues, Types, and Operators