SharedArrayBuffer() constructor

Note: SharedArrayBuffer was disabled by default in all major browsers on 5 January, 2018 in response to Spectre. Chrome re-enabled it in v67 on platforms where its site-isolation feature is enabled to protect against Spectre-style vulnerabilities.

The SharedArrayBuffer() constructor is used to create a SharedArrayBuffer object representing a generic, fixed-length raw binary data buffer, similar to the ArrayBuffer object.

Try it


new SharedArrayBuffer()
new SharedArrayBuffer(length)

Note: SharedArrayBuffer() can only be constructed with new. Attempting to call it without new throws a TypeError.


length Optional

The size, in bytes, of the array buffer to create.

Return value

A new SharedArrayBuffer object of the specified size. Its contents are initialized to 0.


Always use the new operator to create a SharedArrayBuffer

SharedArrayBuffer constructors are required to be constructed with a new operator. Calling a SharedArrayBuffer constructor as a function without new will throw a TypeError.

const sab = SharedArrayBuffer(1024);
// TypeError: calling a builtin SharedArrayBuffer constructor
// without new is forbidden
const sab = new SharedArrayBuffer(1024);


ECMAScript Language Specification
# sec-sharedarraybuffer-constructor

Browser compatibility

BCD tables only load in the browser

See also