Atomics.and() 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 and() function of the Atomic object accepts a value representing the position of an array, performs bitwise AND operation on the value in the given position and returns the old value in it.

Syntax

Its syntax is as follows

Atomics.and()

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

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, 5));
      document.write(", "+Atomics.load(data, 0));
   </script>
</body>
</html>

Output

3,8
raja
Published on 24-Oct-2018 11:04:08
Advertisements