Atomics.compareExchange()
Atomics.compareExchange() is a JavaScript method in the Typed Array category. Exchanges a value if it matches an expected value. The syntax is Atomics.compareExchange(typedArray, index, expected, replacement). A typical example: Atomics.compareExchange(ta, 0, 5, 10). A close sibling is Int8Array, which 8-bit signed integer array. A close sibling is Uint8Array, which 8-bit unsigned integer array. A close sibling is Float64Array, which 64-bit float array. A close sibling is ArrayBuffer, which fixed-length binary buffer. More about this category: Typed arrays for binary data. Related Typed Array methods: Int8Array, Uint8Array, Float64Array, ArrayBuffer, Int32Array, Uint16Array, BigInt64Array, BigUint64Array. This page is part of the free JS Reference documentation covering 1027+ methods, each with syntax, parameters, return values, examples, and common pitfalls. You can try Atomics.compareExchange() immediately in the JavaScript playground, look up unfamiliar terms in the glossary, or return to the JS Reference homepage.