diff --git a/lib/buffer.js b/lib/buffer.js index ee30c69cc9611c..12d730ad463b63 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -860,11 +860,11 @@ Buffer.prototype.equals = function equals(otherBuffer) { if (this === otherBuffer) return true; - - if (this.byteLength !== otherBuffer.byteLength) + const len = this.byteLength; + if (len !== otherBuffer.byteLength) return false; - return this.byteLength === 0 || _compare(this, otherBuffer) === 0; + return len === 0 || _compare(this, otherBuffer) === 0; }; let INSPECT_MAX_BYTES = 50;