Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

node.js

How to use buf.equals() in Node.js

Ayesha Naeem

A buffer buf calls the buf.equals() function on another buffer and checks if the other buffer is equal to buf or not.

Prototype

Parameters and return value

The buf.equals() function accepts a buffer object, otherbuffer, as a single parameter and returns true if buf is equal to otherBuffer; otherwise, it return false.

Example

The following example demonstrates how to use the buf.equals() function in Node.js:

The program creates multiple buffers and tests if they are equal or not.



//create buffers
var buf1 = Buffer.from('Educative.io')

var buf2 = Buffer.from([1,2,3,4])

var buf3 = Buffer.from('Educative.io')

// check if buf1 is equal to buf2
console.log(buf1.equals(buf2))
// check if buf1 is equal to buf3
console.log(buf1.equals(buf3))
// check if buf2 is equal to buf3
console.log(buf2.equals(buf3))

RELATED TAGS

node.js

CONTRIBUTOR

Ayesha Naeem
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring