Favorites

JavaScript Atomics Object

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Atomics
JavaScript Structured Data · NamespaceThis object is supported by all modern browsers.
Updated 28th November 2026

Atomics provides operations that read and change shared memory safely when several threads, such as web workers, use the same SharedArrayBuffer.

Description

The Atomics object is a namespace of atomic operations on integer typed arrays, usually backed by a SharedArrayBuffer. An atomic operation completes in one step, so another thread can't see or interfere with a half-finished change. Methods include add(), sub(), load(), store(), exchange() and compareExchange().

Atomics.wait() and Atomics.notify() let workers sleep until another thread signals them. wait() isn't allowed on the browser's main thread; use Atomics.waitAsync() there instead.

Atomic operations only work on integer typed arrays, such as Int32Array and BigInt64Array, and are mostly meaningful when the array's buffer is shared. They're also used to implement locks, where only one worker at a time may enter a critical section of code. Shared memory and atomics are advanced tools; most web applications communicate between threads by passing messages instead.

Syntax

Atomics.add(typedArray, index, value)
Atomics.load(typedArray, index)
Atomics.wait(typedArray, index, value)

Example

const counter = new Int32Array(new ArrayBuffer(4));
Atomics.add(counter, 0, 10);
Atomics.sub(counter, 0, 3);
console.log(Atomics.load(counter, 0));
console.log(Atomics.compareExchange(counter, 0, 7, 100), counter[0]);

Browser Support

The following information will show you the current browser support for the Atomics object. Hover over a browser icon to see the version that first introduced support for this object.

This object is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee