Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Node.js Buffer.equals() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The Buffer.equals() method is used to compare two buffer objects and returns True of both buffer objects are the same otherwise returns False.

Syntax:

buffer.equals( buf )

Parameters: This method accepts single parameter otherBuffer which holds the another buffer to compare with buffer object.

Return Value: This method returns True if both buffer objects are equal otherwise returns false.

Below examples illustrate the Buffer.equals() method in Node.js:

Example 1:




// Node.js program to demonstrate the   
// Buffer.equals() Method
  
// Create two bufferes
var buf1 = Buffer.from('Hi');
var buf2 = Buffer.from('Hi');
   
// Prints true(boolean value)
console.log(buf1.equals(buf2));

Output:

true

Example 2:




// Node.js program to demonstrate the   
// Buffer.equals() Method
  
// Create two bufferes
var buf1 = Buffer.from('Hi');
var buf2 = Buffer.from('Hello');
  
// Prints false(boolean value)
console.log(buf1.equals(buf2));

Output:

false

Reference: https://nodejs.org/api/buffer.html#buffer_buf_equals_otherbuffer

My Personal Notes arrow_drop_up
Last Updated : 12 Oct, 2021
Like Article
Save Article
Similar Reads
Related Tutorials