Learn JavaScript
❯ collections.typed_arrays

Typed Arrays & ArrayBuffer in JavaScript

$concept

Typed arrays (Uint8Array, Float64Array, ...) are fixed-length views over raw ArrayBuffer memory — numeric computing, binary protocols, WebGL, and audio's native tongue. No holes, no mixed types, no methods that resize: O(1) indexed numeric access with C-like performance characteristics.

DataView reads mixed types and endianness from one buffer (getUint16 with littleEndian flags); TextEncoder/Decoder bridge strings and bytes (UTF-8). Buffers transfer between workers (zero-copy via transferables) — the high-performance JS substrate.

$how it works
1

Buffer plus view

new ArrayBuffer(16) allocates raw bytes; new Uint8Array(buf) views them as numbers — allocation and interpretation separated.

2

Fixed length, numeric only

Length set at construction, elements coerced numerically — out-of-range writes wrap or clamp, never grow.

3

DataView for mixed layouts

getUint16/getFloat32 with endianness flags parse binary formats field by field.

4

Strings cross via codecs

TextEncoder().encode(str) → bytes; TextDecoder().decode(bytes) → str — the UTF-8 bridge.

$example
let buf = new ArrayBuffer(4);
let bytes = new Uint8Array(buf);
bytes[0] = 255;
console.log(bytes.length, bytes[0]);
Output
4 255
1Four raw bytes allocate; the Uint8 view interprets each as 0–255.
2Index 0 stores 255 — length stays fixed at 4 regardless.
3Numeric buffer semantics with zero boxing overhead.
$use cases
Binary protocols and file formats parsed via DataView
Canvas pixel buffers and WebAudio sample arrays
Zero-copy worker transfers of large datasets
String/byte conversion at system boundaries

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in JavaScript yourself — building beats watching.