Atomics.and(typedArray, index, value) combines the element at index with value using the bitwise AND operator (&), stores the result, and returns the element’s old value. A bit stays 1 only if it is 1 in both numbers. That makes and() the tool for switching flags off in a bitmask (a number where each bit means yes or no), while leaving the other flags alone. The whole read-change-write is atomic, so two threads editing different flags of the same shared number cannot undo each other’s work.
Remember
Atomics.and(typedArray, index, mask) -> old value
new value = old & mask
1 & 1 = 1 1 & 0 = 0 0 & 0 = 0
clear a flag: Atomics.and(a, i, ~FLAG)
keep low 4 bits: Atomics.and(a, i, 0b1111)
Syntax
Pass the array, the position, and the mask to AND with.
JavaScript
Atomics.and(typedArray, index, value)
Call
What it does
Atomics.and(typedArray, index, value)
Stores typedArray[index] & value in one atomic step and returns the value from before the change.
Atomics.and(typedArray, index, ~FLAG)
The everyday use: ~FLAG has every bit set except FLAG, so only that one flag is switched off.
Available since ES2017. Its siblings are Atomics.or() (switch flags on) and Atomics.xor() (flip flags).
Library declarations
JavaScript
Atomics.and(typedArray, index, value) // returns the old element value
// stores: typedArray[index] & value
// typedArray: integer typed arrays only (Int8 ... BigUint64)
// value: Number, or BigInt for the BigInt arrays
Parameters
Parameter
Description
typedArray
Required. An integer typed array (Int8Array through BigUint64Array), on a SharedArrayBuffer or a normal ArrayBuffer. Float arrays and Uint8ClampedArray throw a TypeError.
index
Required. The element holding the bits. Out-of-range positions throw a RangeError.
value
Required. The mask. Bits that are 0 in the mask are cleared; bits that are 1 are kept. It is converted to an integer (a BigInt for the BigInt arrays).
Return Value
Return Value
Description
Number or BigInt
The element’s bits before the AND. Compare it with the flag to learn whether the flag was set before you cleared it.
JavaScript Examples
Example 1 — Remove the WRITE Permission
Three permissions share one byte: READ = 1, WRITE = 2, EXEC = 4. AND with ~WRITE removes only WRITE.
Two identical slots. Both elements start as 0b1011, which is 11.
All ones changes nothing. In 32-bit integers -1 is every bit set to 1, so x & -1 is just x. The slot stays 11.
All zeros clears everything.x & 0 is always 0. Both calls still return the old value, 11.
Compatibility
Browser & Runtime Support
Atomics.and() has been part of JavaScript since ES2017.
✓ Baseline · ES2017
Atomics.and()
Works in every modern browser and in Node.js, Deno, and Bun, on both normal and shared integer typed arrays.
95%Modern browser support
Google ChromeModern versions · Desktop & Mobile
Full support
Mozilla FirefoxModern versions · Desktop & Mobile
Full support
Apple SafariModern versions · macOS & iOS
Full support
Microsoft EdgeModern versions · Chromium
Full support
OperaModern versions
Full support
Samsung InternetModern versions · Android
Full support
Internet ExplorerNo Atomics object
Not supported
Node.jsCurrent releases · checked on Node 24
Supported
DenoCurrent releases
Supported
BunCurrent releases
Supported
Atomics.and()Excellent
Bottom line: Safe to use on normal typed arrays anywhere. Sharing a flag word between browser workers additionally requires a cross-origin isolated page for SharedArrayBuffer.
Frequently Asked Questions
It replaces the element with element AND value, bit by bit, in one atomic step, and returns the old element value. A bit survives only when it is 1 in both numbers.
AND with the inverted flag: Atomics.and(flags, 0, ~FLAG). The tilde flips every bit, so the mask has a 0 only where FLAG is and the other flags stay untouched.
That is a read followed by a separate write. On shared memory, another thread could set a different flag in between and your write would erase it. Atomics.and() leaves no gap.
Check the returned old value: (Atomics.and(flags, 0, ~FLAG) & FLAG) !== 0 is true when the flag was on before you cleared it.
Yes. With BigInt64Array or BigUint64Array, pass a BigInt mask such as ~(1n << 40n). Mixing in a Number throws a TypeError.