Atomics.or(typedArray, index, value) combines the element at index with value using bitwise OR (|), stores the result, and returns the element’s old value. A bit becomes 1 if it is 1 in either number, so or() is how you switch flags on without touching the flags that are already set. Because the step is atomic, several threads can each set their own flag in the same shared number and none of the flags gets lost.
Remember
Atomics.or(typedArray, index, mask) -> old value
new value = old | mask
1 | 0 = 1 0 | 1 = 1 0 | 0 = 0
set a flag: Atomics.or(a, i, FLAG)
setting it twice changes nothing
Syntax
Give it the array, the position, and the bits to switch on.
JavaScript
Atomics.or(typedArray, index, value)
Call
What it does
Atomics.or(typedArray, index, value)
Stores typedArray[index] | value in one atomic step and returns the old value.
Atomics.or(typedArray, index, A | B)
Combine flags in the mask first to switch several of them on with a single call.
Available since ES2017. Use Atomics.and() with ~FLAG to switch a flag off again.
Library declarations
JavaScript
Atomics.or(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), shared or not. Float arrays and Uint8ClampedArray are rejected with a TypeError.
index
Required. The element whose bits you set. It must be a valid position, otherwise a RangeError is thrown.
value
Required. The mask of bits to switch on. It is converted to an integer, or must be a BigInt for BigInt64Array and BigUint64Array.
Return Value
Return Value
Description
Number or BigInt
The bits before the OR. If (old & FLAG) !== 0, the flag was already on before your call.
JavaScript Examples
Example 1 — Grant the WRITE Permission
The same READ = 1, WRITE = 2, EXEC = 4 flags as on the and() page. This time or() switches WRITE on, twice.
Bit 40 needs BigInt.1n << 40n is 1099511627776, a value a 32-bit integer cannot hold.
Mask and element must match. Both calls pass BigInts. The second returns the old value, which is exactly bit 40.
Check a high flag. After setting bit 0 the element is 1099511627777, and & FLAG_40 confirms bit 40 is still on.
Compatibility
Browser & Runtime Support
Atomics.or() is an ES2017 feature, supported on shared and normal integer typed arrays.
✓ Baseline · ES2017
Atomics.or()
Available in all modern browsers and in Node.js, Deno, and Bun. The 64-bit BigInt form needs BigInt support, which every modern engine has.
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.or()Excellent
Bottom line: Fine to use everywhere on normal typed arrays. In browsers, sharing the flags with workers needs SharedArrayBuffer, which requires a cross-origin isolated page.
Frequently Asked Questions
The element value from before the OR. The new value is old | mask, and you can compare the old value with your flag to see whether it was already on.
Combine them in the mask: Atomics.or(flags, 0, READ | WRITE). Both bits are switched on in the same atomic step.
No. OR can only turn bits on. To switch a flag off, use Atomics.and(flags, 0, ~FLAG), and to flip it use Atomics.xor().
Each worker sets its own bit with one atomic call, so two workers finishing at the same moment cannot overwrite each other. A plain read-then-write could lose one of the bits.
The extra high bits are dropped when the result is stored, just like any typed array write. Use a wider type such as Uint32Array or BigUint64Array for more flags.