In JavaScript, an ArrayBuffer is a fixed-length block of raw binary memory: a row of bytes, each holding a number from 0 to 255. You create one with new ArrayBuffer(byteLength), and every byte starts at 0.
You cannot read or write the bytes directly. buffer[0] is undefined. Instead you put a view on the buffer: a typed array such as Uint8Array or Float32Array, or a DataView. The view decides how the bytes are interpreted; the buffer only stores them.
You meet ArrayBuffers whenever JavaScript handles binary data: response.arrayBuffer() after fetch, file.arrayBuffer() for an uploaded file, WebSocket binary messages, images, audio, and custom file formats. This page teaches the ideas; the ArrayBuffer Methods index lists every method guide (slice(), transfer(), and more).
Buffer = memory, view = how you read it.
new Uint8Array(buffer)[0] reads the first byte. buffer.byteLength tells you how many bytes there are.
Syntax
JavaScript Syntax
Common ways to create a buffer and look at its bytes:
JavaScript
const buffer = new ArrayBuffer(8); // 8 bytes, all 0
const size = buffer.byteLength; // 8
const bytes = new Uint8Array(buffer); // view: 8 one-byte items
const view = new DataView(buffer); // view: read/write any number type
const copy = buffer.slice(0, 4); // new 4-byte buffer
const growable = new ArrayBuffer(4, { maxByteLength: 64 }); // ES2024
Reference
Core Ideas
Ideas every ArrayBuffer tutorial builds on:
Idea
Example
Remember
Create
new ArrayBuffer(16)
16 bytes, all zero
Size
buffer.byteLength
A property, not a method
Read / write
new Uint8Array(buffer)
Always through a view
Copy
buffer.slice(0, 4)
New, independent buffer
Grow
buffer.resize(32)
Needs maxByteLength (ES2024)
Move
buffer.transfer()
Original becomes detached (ES2024)
Check
ArrayBuffer.isView(x)
True for typed arrays and DataView
Views
Typed Array Views Share Memory
A view never owns bytes; it points at a buffer. You can put several views on the same buffer, and a write through one is immediately visible through all the others. A view can also cover just part of a buffer: new Uint8Array(buffer, 4, 2) starts at byte 4 and is 2 bytes long (its byteOffset and byteLength).
Typed arrays read numbers in the computer's own byte order (little-endian on practically every device today). DataView lets you choose, which is why file formats and network protocols usually use it. To check whether a value is any kind of view, use ArrayBuffer.isView(). Need an independent copy instead of a shared view? Use slice().
ES2024
Resizable Buffers
A normal ArrayBuffer keeps its size forever. Since ES2024 you can opt in to resizing by passing a limit: new ArrayBuffer(8, { maxByteLength: 64 }). The buffer starts at 8 bytes, buffer.resizable is true, and resize() changes its size in place, up to maxByteLength. New bytes are zero. A typed array created without a length follows the buffer as it grows and shrinks.
ES2024
Transferring and Detaching
transfer() moves the bytes into a new ArrayBuffer and leaves the original detached: its byteLength becomes 0, buffer.detached is true, and methods such as slice() throw a TypeError. This is the same ownership hand-off that happens when you send a buffer to a Web Worker with worker.postMessage(buffer, [buffer]). transferToFixedLength() does the same but always returns a fixed-length buffer. Both are ES2024; check support before using them in older browsers.
Compare
ArrayBuffer vs SharedArrayBuffer
Question
ArrayBuffer
SharedArrayBuffer
Who can use it?
One thread at a time
Several workers at the same time
Sending to a worker
Copied, or moved with a transfer list (sender is detached)
Shared: both sides see the same bytes
Coordination
Not needed
Use Atomics to avoid race conditions
Availability
Everywhere
Browsers require a cross-origin isolated page
Code
JavaScript Examples
Three short programs that show how an ArrayBuffer and its views work together.
Example 1 — A New Buffer Is All Zeros
Create a 4-byte buffer, look at it through a Uint8Array, and write two bytes.
An ArrayBuffer is a block of raw binary memory with a fixed number of bytes. You create one with new ArrayBuffer(length) and read or write its bytes through a view such as Uint8Array or DataView.
The buffer only stores bytes; it does not know whether they are 8-bit integers, 32-bit floats, or text. A typed array or DataView decides how to interpret them, so buffer[0] is undefined while new Uint8Array(buffer)[0] is the first byte.
Many web APIs return them: response.arrayBuffer() from fetch, file.arrayBuffer() for a selected file, WebSocket and WebRTC binary messages, and the Web Audio and WebGL APIs. You can also build one yourself for a binary file format or network protocol.
Only if you create it as resizable: new ArrayBuffer(8, { maxByteLength: 64 }). Then resize() changes it in place. That and the transfer methods are ES2024 features, so check support in older browsers.
An ArrayBuffer belongs to one thread at a time and can be transferred, which detaches it. A SharedArrayBuffer can be used by several workers at once and needs Atomics for safe coordination; browsers only enable it on cross-origin isolated pages.