Buffer
Buffer.equals()
Checks whether two byte sequences have identical contents. Tested on Node.js 22.16.0. Do not use ordinary equality comparison as a constant-time cryptographic verification primitive.
Formal Syntax & Structure
nodejs syntaxnodejs
buf.equals(otherBuffer)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| otherBuffer | Buffer | Uint8Array | Bytes to compare. |
Return Value
boolean
Whether lengths and contents match.
Working Example
Example Snippetnodejs
import { Buffer } from 'node:buffer';console.log(Buffer.from('id').equals(Buffer.from('id')),Buffer.from('id').equals(Buffer.from('ID')));