← Lessons

quiz vs the machine

Gold1450

Frontend

The Typed Array and Array Buffer

ArrayBuffer is raw bytes, and typed array views read those bytes as numbers.

5 min read · core · beat Gold to climb

Raw memory and views

An ArrayBuffer is a fixed length block of raw binary data. You cannot touch its bytes directly. Instead you create a typed array view, such as Uint8Array or Float64Array, that interprets the bytes as numbers of a specific type.

  • The buffer holds the bytes, the view gives them meaning.
  • Different views can share one buffer.
  • Indexing a view reads or writes at a typed offset.

Why typed arrays exist

Typed arrays give compact, predictable memory for performance sensitive work like graphics, audio, and binary protocols. They store numbers in a contiguous block with no boxing.

  • WebGL, canvas pixels, and fetch bodies use them.
  • A DataView lets you read mixed types and control byte order.
  • Out of range writes are ignored rather than growing the array.

Because several views can overlap the same buffer, you can reinterpret the same bytes as different types, which is powerful but easy to misuse. The split between buffer and view is the core idea: storage and interpretation are separate concerns.

Key idea

An ArrayBuffer stores raw bytes while typed array views interpret them, letting multiple views share and reinterpret the same memory.

Check yourself

Answer to earn rating on the learn ladder.

1. What does an ArrayBuffer hold?

2. What is the role of a typed array view?

3. What does a DataView add over a typed array?