Using the Atomics.and(typedArray, index, value) method

Atomics.and performs a bitwise AND between the value at that particular index in the typed array and the value you supplied:

const sab = new SharedArrayBuffer(1);const arr = new Uint8Array(sab);arr[0] = 5; // 5 is 0101 in binary.Atomics.and(arr, 0, 12); // 12 is 1100 in binaryconsole.log(Atomics.load(arr, 0));

Atomics.and here performs a bitwise AND between arr[0] and the number 12.

This outputs:

4

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.