Atomics.add() function in JavaScript

JavascriptWeb DevelopmentFront End Scripts

The Atomic object of JavaScript is an object and which provides atomic operations such as add, sub, and, or, xor, load, store etc. as static methods, these methods are used with SharedArrayBuffer objects.

The add() function of this object accepts a number and the position, adds the given number to the number in the given position and returns the value of the number in the old position.

Syntax

Its syntax is as follows

Atomics.add()

Example

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var arrayBuffer = new SharedArrayBuffer(16);
      var data = new Uint8Array(arrayBuffer);
      data[0] = 3;
      document.write(Atomics.add(data, 0, 3));
      document.write(", "+Atomics.load(data, 0));
   </script>
</body>
</html>

Output

3, 6
raja
Published on 24-Oct-2018 11:01:21
Advertisements