Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Node.js | util.types.isSharedArrayBuffer() Method

  • Last Updated : 14 Feb, 2020

The util.types.isSharedArrayBuffer() method of util module is primarily designed to support the needs of Node.js own Internal APIs. It is used to check whether the passed instance in the method is a built-in SharedArrayBuffer instance or not.

Syntax:

util.types.isSharedArrayBuffer( value )

Parameters: This method accepts a single parameter value which holds any value i.e instance of any module.

Return value: This method returns a Boolean value i.e true if the passed value is instance of SharedArrayBuffer otherwise returns false.

Below examples illustrate the use of util.types.isSharedArrayBuffer() method in Node.js:



Example 1:




// Node.js program to demonstrate the    
// util.types.isSharedArrayBuffer() method 
     
// It includes util module 
const util = require('util'); 
     
// Return true as passed instance
// is of SharedArrayBuffer 
console.log(util.types.isSharedArrayBuffer(
                 new SharedArrayBuffer())); 
     
// Return false as passed instance
// is of Int32Array 
console.log(util.types.isSharedArrayBuffer(
                 new Int32Array())); 
   
// Return false as the passed instance is
// of ArrayBuffer, not SharedArrayBuffer
console.log(util.types.isSharedArrayBuffer(
                 new ArrayBuffer()));

Output:

true
false
false

Example 2:




// Node.js program to demonstrate the    
// util.types.isSharedArrayBuffer() method 
     
// It includes util module 
const util = require('util'); 
    
// making an  instance of SharedArrayBuffer
// of size 1024
var sab = new SharedArrayBuffer(1024);
   
// Return true as passed instance is
// of SharedArrayBuffer 
console.log(util.types.isSharedArrayBuffer(sab)); 
     
// Return true as slice method return new
// instance of sharedArrayBuffer 
console.log(util.types.isSharedArrayBuffer(
               sab.slice(100, 199)));

Output:

true
true

Reference: https://nodejs.org/api/util.html#util_util_types_issharedarraybuffer_value




My Personal Notes arrow_drop_up

Start Your Coding Journey Now!