recursal/MDN huggingface dataset:
Reflect.preventExtensions()
===========================

The **`Reflect.preventExtensions()`** static method is like `Object.preventExtensions()`. It prevents new properties from ever being added to an object (i.e., prevents future extensions to the object).

Try it
------

Syntax
------


```js
Reflect.preventExtensions(target)
```

### Parameters

`target`

The target object on which to prevent extensions.

### Return value

A `Boolean` indicating whether or not the target was successfully set to prevent extensions.

### Exceptions

`TypeError`

Thrown if `target` is not an object.

Description
-----------

`Reflect.preventExtensions()` provides the reflective semantic of preventing extensions of an object. The differences with `Object.preventExtensions()` are:

* `Reflect.preventExtensions()` throws a `TypeError` if the target is not an object, while `Object.preventExtensions()` always returns non-object targets as-is.
* `Reflect.preventExtensions()` returns a `Boolean` indicating whether or not the target was successfully set to prevent extensions, while `Object.preventExtensions()` returns the target object.

`Reflect.preventExtensions()` invokes the `[[PreventExtensions]]` object internal method of `target`.

Examples
--------

### Using Reflect.preventExtensions()

See also `Object.preventExtensions()`.


```js
// Objects are extensible by default.
const empty = {};
Reflect.isExtensible(empty); // true

// ...but that can be changed.
Reflect.preventExtensions(empty);
Reflect.isExtensible(empty); // false
```

### Difference with Object.preventExtensions()

If the `target` argument to this method is not an object (a primitive), then it will cause a `TypeError`. With `Object.preventExtensions()`, a non-object `target` will be returned as-is without any errors.


```js
Reflect.preventExtensions(1);
// TypeError: 1 is not an object

Object.preventExtensions(1);
// 1
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-reflect.preventextensions |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Reflect.preventExtensions` in `core-js`
* `Reflect`
* `Object.preventExtensions()`
* `handler.preventExtensions()`
Uint8ClampedArray() constructor
===============================

The **`Uint8ClampedArray()`** constructor creates `Uint8ClampedArray` objects. The contents are initialized to `0`.

Syntax
------


```js
new Uint8ClampedArray()
new Uint8ClampedArray(length)
new Uint8ClampedArray(typedArray)
new Uint8ClampedArray(object)

new Uint8ClampedArray(buffer)
new Uint8ClampedArray(buffer, byteOffset)
new Uint8ClampedArray(buffer, byteOffset, length)
```


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

### Parameters

See `TypedArray`.

### Exceptions

See `TypedArray`.

Examples
--------

### Different ways to create a Uint8ClampedArray


```js
// From a length
const uint8c = new Uint8ClampedArray(2);
uint8c[0] = 42;
uint8c[1] = 1337;
console.log(uint8c[0]); // 42
console.log(uint8c[1]); // 255 (clamped)
console.log(uint8c.length); // 2
console.log(uint8c.BYTES\_PER\_ELEMENT); // 1

// From an array
const x = new Uint8ClampedArray([21, 31]);
console.log(x[1]); // 31

// From another TypedArray
const y = new Uint8ClampedArray(x);
console.log(y[0]); // 21

// From an ArrayBuffer
const buffer = new ArrayBuffer(8);
const z = new Uint8ClampedArray(buffer, 1, 4);
console.log(z.byteOffset); // 1

// From an iterable
const iterable = (function\* () {
  yield\* [1, 2, 3];
})();
const uint8cFromIterable = new Uint8ClampedArray(iterable);
console.log(uint8cFromIterable);
// Uint8ClampedArray [1, 2, 3]
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-typedarray-constructors |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Uint8ClampedArray` in `core-js`
* JavaScript typed arrays guide
* `TypedArray`
* `ArrayBuffer`
* `DataView`
Atomics.and()
=============

 The **`Atomics.and()`** static
 method computes a bitwise AND with a given value at a given position in the array, and
 returns the old value at that position. This atomic operation guarantees that no other
 write happens until the modified value is written back.

Try it
------

Syntax
------


```js
Atomics.and(typedArray, index, value)
```

### Parameters

`typedArray`

 An integer typed array. One of `Int8Array`, `Uint8Array`,
 `Int16Array`, `Uint16Array`, `Int32Array`,
 `Uint32Array`, `BigInt64Array`, or
 `BigUint64Array`.


`index`

The position in the `typedArray` to compute the bitwise AND.

`value`

The number to compute the bitwise AND with.

### Return value

 The old value at the given position
 (`typedArray[index]`).

### Exceptions

`TypeError`

Thrown if `typedArray` is not one of the allowed integer types.

`RangeError`

Thrown if `index` is out of bounds in the `typedArray`.

Description
-----------

 The bitwise AND operation only yields 1, if both `a` and `b` are
 1. The truth table for the AND operation is:


| `a` | `b` | `a & b` |
| --- | --- | --- |
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |

 For example, a bitwise AND of `5 & 1` results in `0001` which
 is 1 in decimal.
```

5  0101
1  0001
   ----
1  0001
```

Examples
--------

### Using and()


```js
const sab = new SharedArrayBuffer(1024);
const ta = new Uint8Array(sab);
ta[0] = 5;

Atomics.and(ta, 0, 1); // returns 5, the old value
Atomics.load(ta, 0); // 1
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-atomics.and |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Atomics`
* `Atomics.or()`
* `Atomics.xor()`
Atomics.or()
============

 The **`Atomics.or()`** static
 method computes a bitwise OR with a given value at a given position in the array, and
 returns the old value at that position. This atomic operation guarantees that no other
 write happens until the modified value is written back.

Try it
------

Syntax
------


```js
Atomics.or(typedArray, index, value)
```

### Parameters

`typedArray`

 An integer typed array. One of `Int8Array`, `Uint8Array`,
 `Int16Array`, `Uint16Array`, `Int32Array`,
 `Uint32Array`, `BigInt64Array`, or
 `BigUint64Array`.


`index`

The position in the `typedArray` to compute the bitwise OR.

`value`

The number to compute the bitwise OR with.

### Return value

 The old value at the given position
 (`typedArray[index]`).

### Exceptions

`TypeError`

Thrown if `typedArray` is not one of the allowed integer types.

`RangeError`

Thrown if `index` is out of bounds in the `typedArray`.

Description
-----------

 The bitwise OR operation yields 1, if either `a` or `b` are 1.
 The truth table for the OR operation is:


| `a` | `b` | `a | b` |
| --- | --- | --- |
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |

 For example, a bitwise OR of `5 | 1` results in `0101` which is 5
 in decimal.
```

5  0101
1  0001
   ----
5  0101
```

Examples
--------

### Using or


```js
const sab = new SharedArrayBuffer(1024);
const ta = new Uint8Array(sab);
ta[0] = 2;

Atomics.or(ta, 0, 1); // returns 2, the old value
Atomics.load(ta, 0); // 3
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-atomics.or |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Atomics`
* `Atomics.and()`
* `Atomics.xor()`
Atomics.store()
===============

 The **`Atomics.store()`** static
 method stores a given value at the given position in the array and returns that value.

Try it
------

Syntax
------


```js
Atomics.store(typedArray, index, value)
```

### Parameters

`typedArray`

 An integer typed array. One of `Int8Array`, `Uint8Array`,
 `Int16Array`, `Uint16Array`, `Int32Array`,
 `Uint32Array`, `BigInt64Array`, or
 `BigUint64Array`.


`index`

 The position in the `typedArray` to store a
 `value` in.


`value`

The number to store.

### Return value

The value that has been stored.

### Exceptions

`TypeError`

Thrown if `typedArray` is not one of the allowed integer types.

`RangeError`

Thrown if `index` is out of bounds in the `typedArray`.

Examples
--------

### Using store()


```js
const sab = new SharedArrayBuffer(1024);
const ta = new Uint8Array(sab);

Atomics.store(ta, 0, 12); // 12
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-atomics.store |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Atomics`
* `Atomics.load()`
Atomics.sub()
=============

 The **`Atomics.sub()`** static method subtracts a given value
 at a given position in the array and returns the old value at that position. This atomic
 operation guarantees that no other write happens until the modified value is written
 back.

Try it
------

Syntax
------


```js
Atomics.sub(typedArray, index, value)
```

### Parameters

`typedArray`

 An integer typed array. One of `Int8Array`, `Uint8Array`,
 `Int16Array`, `Uint16Array`, `Int32Array`,
 `Uint32Array`, `BigInt64Array`, or
 `BigUint64Array`.


`index`

 The position in the `typedArray` to subtract a
 `value` from.


`value`

The number to subtract.

### Return value

 The old value at the given position
 (`typedArray[index]`).

### Exceptions

`TypeError`

Thrown if `typedArray` is not one of the allowed integer types.

`RangeError`

Thrown if `index` is out of bounds in the `typedArray`.

Examples
--------

### Using sub


```js
const sab = new SharedArrayBuffer(1024);
const ta = new Uint8Array(sab);
ta[0] = 48;

Atomics.sub(ta, 0, 12); // returns 48, the old value
Atomics.load(ta, 0); // 36
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-atomics.sub |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Atomics`
* `Atomics.add()`
Atomics.xor()
=============

 The **`Atomics.xor()`** static
 method computes a bitwise XOR with a given value at a given position in the array, and
 returns the old value at that position. This atomic operation guarantees that no other
 write happens until the modified value is written back.

Try it
------

Syntax
------


```js
Atomics.xor(typedArray, index, value)
```

### Parameters

`typedArray`

 An integer typed array. One of `Int8Array`, `Uint8Array`,
 `Int16Array`, `Uint16Array`, `Int32Array`,
 `Uint32Array`, `BigInt64Array`, or
 `BigUint64Array`.


`index`

The position in the `typedArray` to compute the bitwise XOR.

`value`

The number to compute the bitwise XOR with.

### Return value

The old value at the given position (`typedArray[index]`).

### Exceptions

`TypeError`

Thrown if `typedArray` is not one of the allowed integer types.

`RangeError`

Thrown if `index` is out of bounds in the `typedArray`.

Description
-----------

 The bitwise XOR operation yields 1, if `a` and `b` are different.
 The truth table for the XOR operation is:


| `a` | `b` | `a ^ b` |
| --- | --- | --- |
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |

 For example, a bitwise XOR of `5 ^ 1` results in `0100` which is
 4 in decimal.
```

5  0101
1  0001
   ----
4  0100
```

Examples
--------

### Using xor


```js
const sab = new SharedArrayBuffer(1024);
const ta = new Uint8Array(sab);
ta[0] = 5;

Atomics.xor(ta, 0, 1); // returns 5, the old value
Atomics.load(ta, 0); // 4
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-atomics.xor |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Atomics`
* `Atomics.and()`
* `Atomics.or()`
Atomics.exchange()
==================

The **`Atomics.exchange()`** static method exchanges a given value at a given position in the array and returns the old value at that position. This atomic operation guarantees that no other write happens between the read of the old value and the write of the new value.

Try it
------

Syntax
------


```js
Atomics.exchange(typedArray, index, value)
```

### Parameters

`typedArray`

An integer typed array. One of `Int8Array`, `Uint8Array`, `Int16Array`, `Uint16Array`, `Int32Array`, `Uint32Array`, `BigInt64Array`, or `BigUint64Array`.

`index`

The position in the `typedArray` to exchange a `value`.

`value`

The number to exchange.

### Return value

The old value at the given position (`typedArray[index]`).

### Exceptions

`TypeError`

Thrown if `typedArray` is not one of the allowed integer types.

`RangeError`

Thrown if `index` is out of bounds in the `typedArray`.

Examples
--------

### Using exchange()


```js
const sab = new SharedArrayBuffer(1024);
const ta = new Uint8Array(sab);

Atomics.exchange(ta, 0, 12); // returns 0, the old value
Atomics.load(ta, 0); // 12
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-atomics.exchange |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Atomics`
* `Atomics.compareExchange()`
Atomics.load()
==============

 The **`Atomics.load()`** static
 method returns a value at a given position in the array.

Try it
------

Syntax
------


```js
Atomics.load(typedArray, index)
```

### Parameters

`typedArray`

 An integer typed array. One of `Int8Array`, `Uint8Array`,
 `Int16Array`, `Uint16Array`, `Int32Array`,
 `Uint32Array`, `BigInt64Array`, or
 `BigUint64Array`.


`index`

The position in the `typedArray` to load from.

### Return value

The value at the given position (`typedArray[index]`).

### Exceptions

`TypeError`

Thrown if `typedArray` is not one of the allowed integer types.

`RangeError`

Thrown if `index` is out of bounds in the `typedArray`.

Examples
--------

### Using `load`


```js
const sab = new SharedArrayBuffer(1024);
const ta = new Uint8Array(sab);

Atomics.add(ta, 0, 12);
Atomics.load(ta, 0); // 12
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-atomics.load |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Atomics`
* `Atomics.store()`
Atomics.waitAsync()
===================

The **`Atomics.waitAsync()`** static method waits asynchronously on a shared memory location and returns a `Promise`.

Unlike `Atomics.wait()`, `waitAsync` is non-blocking and usable on the main thread.

**Note:** This operation only works with an `Int32Array` or `BigInt64Array` that views a `SharedArrayBuffer`.

Syntax
------


```js
Atomics.waitAsync(typedArray, index, value)
Atomics.waitAsync(typedArray, index, value, timeout)
```

### Parameters

`typedArray`

An `Int32Array` or `BigInt64Array` that views a `SharedArrayBuffer`.

`index`

The position in the `typedArray` to wait on.

`value`

The expected value to test.

`timeout` Optional

Time to wait in milliseconds. `NaN` (and values that get converted to `NaN`, such as `undefined`) becomes `Infinity`. Negative values become `0`.

### Return value

An `Object` with the following properties:

`async`

A boolean indicating whether the `value` property is a `Promise` or not.

`value`

If `async` is `false`, it will be a string which is either `"not-equal"` or `"timed-out"` (only when the `timeout` parameter is `0`). If `async` is `true`, it will be a `Promise` which is fulfilled with a string value, either `"ok"` or `"timed-out"`. The promise is never rejected.

### Exceptions

`TypeError`

Thrown if `typedArray` is not an `Int32Array` or `BigInt64Array` that views a `SharedArrayBuffer`.

`RangeError`

Thrown if `index` is out of bounds in the `typedArray`.

Examples
--------

### Using waitAsync()

Given a shared `Int32Array`.


```js
const sab = new SharedArrayBuffer(1024);
const int32 = new Int32Array(sab);
```


 A reading thread is sleeping and waiting on location 0 which is expected to be 0.
 The `result.value` will be a promise.


```js
const result = Atomics.waitAsync(int32, 0, 0, 1000);
// { async: true, value: Promise {<pending>} }
```


In the reading thread or in another thread, the memory location 0 is called and the promise can be resolved with `"ok"`.


```js
Atomics.notify(int32, 0);
// { async: true, value: Promise {<fulfilled>: 'ok'} }
```


If it isn't resolving to `"ok"`, the value in the shared memory location wasn't the expected (the `value` would be `"not-equal"` instead of a promise) or the timeout was reached (the promise will resolve to `"time-out"`).

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-atomics.waitasync |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Atomics`
* `Atomics.wait()`
* `Atomics.notify()`
Atomics.compareExchange()
=========================

The **`Atomics.compareExchange()`** static method exchanges a given replacement value at a given position in the array, if a given expected value equals the old value. It returns the old value at that position whether it was equal to the expected value or not. This atomic operation guarantees that no other write happens until the modified value is written back.

Try it
------

Syntax
------


```js
Atomics.compareExchange(typedArray, index, expectedValue, replacementValue)
```

### Parameters

`typedArray`

An integer typed array. One of `Int8Array`, `Uint8Array`, `Int16Array`, `Uint16Array`, `Int32Array`, `Uint32Array`, `BigInt64Array`, or `BigUint64Array`.

`index`

The position in the `typedArray` to exchange a `replacementValue`.

`expectedValue`

The value to check for equality.

`replacementValue`

The number to exchange.

### Return value

The old value at the given position (`typedArray[index]`).

### Exceptions

`TypeError`

Thrown if `typedArray` is not one of the allowed integer types.

`RangeError`

Thrown if `index` is out of bounds in the `typedArray`.

Examples
--------

### Using compareExchange()


```js
const sab = new SharedArrayBuffer(1024);
const ta = new Uint8Array(sab);
ta[0] = 7;

Atomics.compareExchange(ta, 0, 7, 12); // returns 7, the old value
Atomics.load(ta, 0); // 12
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-atomics.compareexchange |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Atomics`
* `Atomics.exchange()`
Atomics.notify()
================

 The **`Atomics.notify()`** static
 method notifies up some agents that are sleeping in the wait queue.


**Note:** This operation only works with an `Int32Array` or `BigInt64Array` that views a `SharedArrayBuffer`.
 It will return `0` on non-shared `ArrayBuffer` objects.


Syntax
------


```js
Atomics.notify(typedArray, index, count)
```

### Parameters

`typedArray`

An `Int32Array` or `BigInt64Array` that views a `SharedArrayBuffer`.

`index`

The position in the `typedArray` to wake up on.

`count` Optional

The number of sleeping agents to notify. Defaults to `Infinity`.

### Return value

* Returns the number of woken up agents.
* Returns `0`, if a non-shared `ArrayBuffer` object is used.
### Exceptions

`TypeError`

Thrown if `typedArray` is not an `Int32Array` or `BigInt64Array` that views a `SharedArrayBuffer`.

`RangeError`

Thrown if `index` is out of bounds in the `typedArray`.

Examples
--------

### Using `notify`

Given a shared `Int32Array`:


```js
const sab = new SharedArrayBuffer(1024);
const int32 = new Int32Array(sab);
```


 A reading thread is sleeping and waiting on location 0 which is expected to be 0. As
 long as that is true, it will not go on. However, once the writing thread has stored a
 new value, it will be notified by the writing thread and return the new value (123).


```js
Atomics.wait(int32, 0, 0);
console.log(int32[0]); // 123
```


 A writing thread stores a new value and notifies the waiting thread once it has
 written:


```js
console.log(int32[0]); // 0;
Atomics.store(int32, 0, 123);
Atomics.notify(int32, 0, 1);
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-atomics.notify |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Atomics`
* `Atomics.wait()`
* `Atomics.waitAsync()`
Atomics.isLockFree()
====================

 The **`Atomics.isLockFree()`** static
 method is used to determine whether the `Atomics` methods use locks
 or atomic hardware operations when applied to typed arrays with the given element
 byte size.
 It returns `false` if the given size is not one of the BYTES\_PER\_ELEMENT
 property of integer TypedArray types.

Try it
------

Syntax
------


```js
Atomics.isLockFree(size)
```

### Parameters

`size`

The size in bytes to check.

### Return value

A `true` or `false` value indicating whether the operation is lock free.

Examples
--------

### Using isLockFree


```js
Atomics.isLockFree(1); // true
Atomics.isLockFree(2); // true
Atomics.isLockFree(3); // false
Atomics.isLockFree(4); // true
Atomics.isLockFree(5); // false
Atomics.isLockFree(6); // false
Atomics.isLockFree(7); // false
Atomics.isLockFree(8); // true
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-atomics.islockfree |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Atomics`
Atomics.add()
=============

 The **`Atomics.add()`** static
 method adds a given value at a given position in the array and returns the old value at
 that position. This atomic operation guarantees that no other write happens until the
 modified value is written back.

Try it
------

Syntax
------


```js
Atomics.add(typedArray, index, value)
```

### Parameters

`typedArray`

 An integer typed array. One of `Int8Array`, `Uint8Array`,
 `Int16Array`, `Uint16Array`, `Int32Array`,
 `Uint32Array`, `BigInt64Array`, or
 `BigUint64Array`.


`index`

 The position in the `typedArray` to add a
 `value` to.


`value`

The number to add.

### Return value

 The old value at the given position
 (`typedArray[index]`).

### Exceptions

`TypeError`

Thrown if `typedArray` is not one of the allowed integer types.

`RangeError`

Thrown if `index` is out of bounds in the `typedArray`.

Examples
--------

### Using add()


```js
const sab = new SharedArrayBuffer(1024);
const ta = new Uint8Array(sab);

Atomics.add(ta, 0, 12); // returns 0, the old value
Atomics.load(ta, 0); // 12
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-atomics.add |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Atomics`
* `Atomics.sub()`