JavaScript Atomics isLockFree() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
Atomics

Definition

Atomics.isLockFree(size) answers a question about the engine, not about your data: for elements that are size bytes long, are the Atomics operations done with the CPU’s own atomic instructions (lock-free), or does the engine need an internal lock to fake them? It returns true or false and does not take a typed array at all. The rules are simple: isLockFree(4) is always true, sizes 1, 2, and 8 depend on the engine and the hardware (they are usually true on today’s computers), and every other size is false. Your Atomics code works either way; the answer only matters for advanced performance tuning.

Remember
Atomics.isLockFree(size)   -> true or false

isLockFree(4)         -> always true (Int32Array, Uint32Array)
isLockFree(1, 2, 8)   -> engine and hardware decide
isLockFree(3, 16 ...) -> false

no typed array needed; nothing is read or written

Syntax

It takes one argument: a size in bytes.

JavaScript
Atomics.isLockFree(size)
CallWhat it does
Atomics.isLockFree(size)Returns true when atomic operations on size-byte elements are lock-free on this engine, otherwise false.
Atomics.isLockFree(Int32Array.BYTES_PER_ELEMENT)Ask about a typed array type by passing its element size: 1 for Int8Array, 2 for Int16Array, 4 for Int32Array, 8 for BigInt64Array.

Available since ES2017. It is the only Atomics method that never touches a typed array.

Library declarations
JavaScript
Atomics.isLockFree(size)   // returns a boolean

// size is converted to a number first; pass whole numbers
// 4          -> true on every engine
// 1, 2, 8    -> implementation-defined
// any other  -> false

Parameters

ParameterDescription
sizeRequired. An element size in bytes. It is converted to a number, so "4" counts as 4, and null or a missing argument count as 0. Pass whole numbers: for a fraction such as 4.9, engines do not all give the same answer (Node.js 24 says false).

Return Value

Return ValueDescription
trueOperations on elements of this size use hardware atomic instructions.
falseThe size is not lock-free here, or it is not a size any integer typed array uses (for example 3 or 16).

JavaScript Examples

Example 1 — The Answers Every Engine Agrees On

Size 4 is always lock-free. Sizes that no integer typed array uses are always reported as not lock-free.

JavaScript
console.log(Atomics.isLockFree(4));    // true
console.log(Atomics.isLockFree(3));    // false
console.log(Atomics.isLockFree(16));   // false
Try It Yourself

How It Works

  1. Four bytes is guaranteed. The language requires isLockFree(4) to be true, which is one reason Int32Array is the standard choice for Atomics.
  2. Three bytes does not exist. No typed array has 3-byte elements, so the answer is false.
  3. Sixteen bytes is not offered. Atomics has no 128-bit operations, so 16 is false too.

Example 2 — Check Each Typed Array Size

Loop over four typed array types and pass each one’s BYTES_PER_ELEMENT. The output shown is from Node.js 24 on a common 64-bit computer.

JavaScript
const types = [Int8Array, Int16Array, Int32Array, BigInt64Array];

types.forEach(function (Type) {
  const size = Type.BYTES_PER_ELEMENT;
  console.log(Type.name + " (" + size + " bytes): " + Atomics.isLockFree(size));
});
Try It Yourself

How It Works

  1. Every typed array knows its size. BYTES_PER_ELEMENT is 1, 2, 4, or 8 for these four types.
  2. Ask once per size. isLockFree() only needs the number, so the loop never creates an array.
  3. Expect differences elsewhere. Only the 4-byte line is guaranteed. On other engines or CPUs the 1-, 2-, or 8-byte lines may print false.

Example 3 — The Size Is Converted to a Number

isLockFree() does not throw for odd input. It converts the argument to a number first.

JavaScript
console.log(Atomics.isLockFree("4"));    // true
console.log(Atomics.isLockFree(null));   // false
console.log(Atomics.isLockFree());       // false
console.log(Atomics.isLockFree(-4));     // false
Try It Yourself

How It Works

  1. Strings become numbers. "4" is converted to 4, so the answer is true.
  2. Empty values count as 0. null and a missing argument both become 0, and no element is 0 bytes long, so both are false.
  3. Stick to whole, positive sizes. -4 is not a valid size, so it is false. Fractions such as 4.9 are best avoided: engines do not all agree on them.

Browser & Runtime Support

Atomics.isLockFree() is part of ES2017. It needs no SharedArrayBuffer, so it runs on any page.

✓ Baseline · ES2017

Atomics.isLockFree()

Available in all modern browsers and in Node.js, Deno, and Bun. The answers for sizes 1, 2, and 8 are engine and hardware dependent.

95% Modern browser support
Google Chrome Modern versions · Desktop & Mobile
Full support
Mozilla Firefox Modern versions · Desktop & Mobile
Full support
Apple Safari Modern versions · macOS & iOS
Full support
Microsoft Edge Modern versions · Chromium
Full support
Opera Modern versions
Full support
Samsung Internet Modern versions · Android
Full support
Internet Explorer No Atomics object
Not supported
Node.js Current releases · checked on Node 24
Supported
Deno Current releases
Supported
Bun Current releases
Supported
Atomics.isLockFree() Excellent

Bottom line: Calling it is safe everywhere, including normal (not cross-origin isolated) browser tabs. Treat every answer except the one for size 4 as information, not as a guarantee.

Frequently Asked Questions

Whether atomic operations on elements of the given byte size are done directly by the hardware on this engine. It does not look at any data.
Yes. The language requires it, which is one reason Int32Array is the usual choice for shared counters and for Atomics.wait() and Atomics.notify().
Those answers are left to the engine. They depend on the CPU and on how the engine was built, so they can change between platforms.
No. They are still atomic; the engine just uses an internal lock to make them so, which can be slower.
No. It takes only a number, so it works on any page and in any runtime that has the Atomics object.

Next: Atomics.load()

Read a shared value safely, and see why load() is stricter than brackets.

load() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful