FSM Full Stack Masterclass
Platform under construction
JavaScript course badge

JSON & Structured Data

Advanced

ArrayBuffer, DataView & Atomics

ArrayBuffer stores raw bytes. DataView reads those bytes with explicit types and byte order. Atomics coordinates shared memory.

const buffer = new ArrayBuffer(4);
const view = new DataView(buffer);

view.setUint16(0, 513, false);
console.log(view.getUint16(0, false));

JSON & Structured Data

ArrayBuffer is the bytes; DataView is precise reading and writing.

ArrayBuffer is a fixed-length raw byte buffer. It does not say what the bytes mean by itself.

DataView lets you read and write numbers at byte offsets with explicit endianness. This matters for binary formats and network protocols.

Atomics works with SharedArrayBuffer and integer typed arrays to coordinate memory between threads. It is specialized and should be used carefully.

ArrayBuffer

Raw fixed-length bytes.

DataView

Reads and writes typed values at byte offsets.

Endianness

Byte order: big-endian or little-endian.

Atomics

Safe shared-memory operations for workers.

Examples

Structured data code should show the boundary clearly.

DataView with explicit byte order

const view = new DataView(new ArrayBuffer(4));

view.setUint16(0, 513, false);
const value = view.getUint16(0, false);

Binary code with hidden byte order

view.setUint16(0, 513);
const value = view.getUint16(0);

// Readers cannot see whether byte order was intentional.

Code patterns

Reusable examples for quick reference.

These patterns focus on the data boundaries you will use constantly: JSON, URLs, forms, files, fetch objects and binary buffers.

Create buffer

Allocate raw bytes.

const buffer = new ArrayBuffer(8);

DataView write/read

Use byte offsets and explicit type.

const view = new DataView(buffer);
view.setUint16(0, 513, false);
console.log(view.getUint16(0, false));

Little-endian read

The third argument controls byte order.

view.setUint16(0, 513, true);
console.log(view.getUint16(0, true));

Atomics guard

Use feature checks for shared memory support.

if (typeof SharedArrayBuffer !== "undefined") {
  const shared = new SharedArrayBuffer(4);
  const values = new Int32Array(shared);
  Atomics.add(values, 0, 1);
}

Rules that matter

Parse, validate and convert data at the edges.

Structured data becomes reliable when every boundary is explicit: text to object, form to values, URL to parameters, response to JSON and bytes to meaning.

Use ArrayBuffer for raw bytes

The buffer stores bytes, not meaning.

Use DataView for structured binary fields

Offsets and types stay explicit.

Always document byte order

Endianness bugs are hard to spot.

Validate offsets and sizes

Binary reads can go out of range.

Use Atomics only for shared memory

Most application code does not need it.

Feature-check SharedArrayBuffer

Browser security requirements can affect availability.

Production thinking

Trust data only after the code has proved its shape.

Why does this matter?

Structured binary code needs precision. DataView makes byte offset, type and byte order visible.

Accessibility

Binary processing errors should become clear UI messages instead of silent failures.

Production note

Production binary parsers should test byte order, invalid sizes and unsupported shared memory paths.

SEO note

Binary APIs do not affect crawled text directly, but generated data should be labeled clearly when displayed.

Live code lab

Change the HTML, CSS or JavaScript and run the result.

The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.

Mini assignment

Try this now.

  • Change big-endian to little-endian and inspect the bytes.
  • Try reading from an invalid offset.
  • Add a SharedArrayBuffer feature check.

Practice assignment

Do this before moving to the next topic.

  1. Create an ArrayBuffer.
  2. Write one value with DataView.
  3. Read it with the same byte order.

Try it yourself

Read numbers from an ArrayBuffer

Live preview

Self-check

Before you continue, prove that you understand ArrayBuffer, DataView & Atomics.

Advanced

Structured data is safe only when you know where it came from, what shape it has and what conversion happened before use.

  1. Can you explain ArrayBuffer?
  2. Can you explain DataView?
  3. Can you explain byte offset?
  4. Can you explain endianness?
  5. Can you explain why Atomics is specialized?

Senior audit upgrade

Extra production context for ArrayBuffer, DataView & Atomics.

Optional advanced topic

Atomics and SharedArrayBuffer are specialized tools for concurrent work. Learn the concept, but do not treat it as day-one web development.

Compatibility note: Atomics

Last reviewed: 11 June 2026. Browser Atomics often depends on SharedArrayBuffer and cross-origin isolation. Treat it as specialized infrastructure work.

Chapter checkpoint

JSON & Structured Data checkpoint

Finish this chapter by turning the lessons into a small practical proof.

Build

Build a small example that combines three lessons from this chapter.

Deliverables

  • working code
  • short explanation
  • self-check answers

Quality checks

  • readable code
  • clear failure path
  • accessibility considered

Review question

Can you explain the important tradeoff without reading from the page?