Lodash _.isBuffer() method

Beginner
⏱️ 6 min read
📚 Updated: May 2026
🎯 3 Code examples
🚀 3 Try-it labs
Lodash

What you’ll learn

  • How _.isBuffer(value) ties to Buffer.isBuffer in Node.
  • Why Uint8Array and ArrayBuffer are not Buffers.
  • Browser vs server considerations for binary APIs.
  • When to normalize bytes with Buffer.from or typed arrays instead.

Prerequisites

Basic familiarity with Node.js buffers or comparable APIs from tooling tutorials.

  • You know binary data appears as bytes, not UTF‑16 text strings.
  • You can open Try-it labs: positive-buffer runs polyfill Buffer and call Buffer.isBuffer (CDN lodash cannot bind _.isBuffer to it).

Overview

Reach for _.isBuffer when validating streams, file reads, crypto digests, or middleware bodies delivered as Node Buffers—especially alongside lodash-heavy server utilities.

Node-first

Mirrors the runtime’s native Buffer branding checks.

Not typed arrays

Reject arbitrary Uint8Array unless your pipeline wraps them as Buffer.

Polyfill aware

Browsers need Buffer implementations—lodash cannot invent them.

Syntax

javascript
_.isBuffer(value)
  • value: any value to test.
  • Returns: true if value is a Buffer (per Buffer.isBuffer when available); otherwise false.
1

Buffer.from and Buffer.alloc

Typical constructors emit real Buffer instances, which lodash recognizes immediately.

javascript
import isBuffer from "lodash/isBuffer";

console.log(
  "fromUtf8: " + isBuffer(Buffer.from("hello", "utf8")) + "\n" +
  "allocBytes: " + isBuffer(Buffer.alloc(16))
);
Try it Yourself
2

Typed arrays, ArrayBuffers, and strings

These values carry bytes or characters but are not Node Buffer instances—convert explicitly when your API requires Buffer.

javascript
import isBuffer from "lodash/isBuffer";

console.log(
  "uint8View: " + isBuffer(new Uint8Array(4)) + "\n" +
  "rawArrayBuffer: " + isBuffer(new ArrayBuffer(8)) + "\n" +
  "plainString: " + isBuffer("binary-string")
);
Try it Yourself
3

Wrapping typed arrays as Buffer

When interoperating with typed arrays, copy or wrap—then _.isBuffer succeeds.

javascript
import isBuffer from "lodash/isBuffer";

var view = new Uint8Array([1, 2, 3]);

console.log(
  "typedOnly: " + isBuffer(view) + "\n" +
  "wrappedCopy: " + isBuffer(Buffer.from(view))
);
Try it Yourself

📋 _.isBuffer vs related checks

APIMatches
_.isBuffer(x)Node Buffer instances (via Buffer.isBuffer).
_.isTypedArray(x)Uint8Array, Float64Array, etc.
_.isArrayBuffer(x)Underlying raw ArrayBuffer objects.
_.isArrayLike(x)Broad collections—including Buffers when treated as indexed objects.

Pitfalls to avoid

Bundles

Multiple Buffer copies

Bundlers may shim Buffer differently across chunks—prefer one consistent polyfill per app.

Fetch

arrayBuffer() vs Buffer

Fetch resolves ArrayBuffer; call Buffer.from on the server after reading bytes.

Globals

CDN lodash vs Buffer

Bare lodash.min.js cannot bind _.isBuffer to Buffer.isBuffer; polyfills arrive too late. Prefer bundlers with Node shims or call Buffer.isBuffer directly in scripts.

❓ FAQ

No. ArrayBuffer is raw memory; Node Buffer is a Uint8Array-backed view with extra APIs. _.isBuffer targets Buffer instances only.
Usually no. Although Buffer extends Uint8Array in Node, lodash (via Buffer.isBuffer) distinguishes real Buffer instances from plain typed-array views.
In bundled apps that shim Buffer before Lodash loads, yes—it forwards to Buffer.isBuffer like Node. If you drop lodash.min.js into plain HTML, the compiled _.isBuffer is wired to always return false—even after you polyfill Buffer—because that build never hooks Buffer.isBuffer. Use Buffer.isBuffer in raw demos or bundle with Buffer exposed during Lodash init.
For isomorphic code, yes—guard typeof Buffer !== "undefined" when running in browsers without polyfills.

Summary

  • Purpose: detect Node Buffer instances portably inside lodash.
  • Exclude: typed-array views and raw ArrayBuffer unless wrapped.
  • Next: explore more on Lodash _.isDate().
Did you know?

_.isBuffer compiles to Buffer.isBuffer only when Lodash can resolve Buffer via its CommonJS bootstrap path (Node and typical bundlers). The lodash.min.js CDN script used in bare browsers binds _.isBuffer to always-false; polyfilling Buffer later does not change that—call Buffer.isBuffer directly or bundle Lodash with Node-style globals.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful