Node.js | Buffer.isBuffer() Method
Buffer is a temporary memory storage which stores the data when it is being moved from one place to another. It is like an array of integers.
The Buffer.isBuffer() method checks whether the provided object is a buffer or not.
Syntax:
Buffer.isBuffer( obj )
Parameters: This method accepts single parameter obj which need to be checked if it is a buffer or not.
Return Value: This method returns a Boolean Value, true if the object is buffer, otherwise returns false.
Below examples illustrate the use of Buffer.isBuffer() Method in Node.js:
Example 1:
// Node.js program to demonstrate the // Buffer.isBuffer() Method var buffer = Buffer.from('GeeksForGeeks'); console.log(Buffer.isBuffer(buffer)); |
Output
true
Example 2:
// Node.js program to demonstrate the // Buffer.isBuffer()) Method var buf1 = "GeeksforGeeks"; console.log(Buffer.isBuffer(buf1)); var buf2 = new Buffer(4); for (var i = 0 ; i < 4 ; i++) { buf2[i] = i + 97;} // Prints: abcd// as 97, 98, 99, 100 are the ASCII // values of these chars respectively console.log(buf2.toString()); console.log(Buffer.isBuffer(buf2));// Prints: true |
Output:
false abcd true
Note: The above program will compile and run by using the node index.js command.
Reference: https://nodejs.org/api/buffer.html#buffer_class_method_buffer_isbuffer_obj


