Allocating a filled buffer makes each initial byte predictable. This matters when preparing binary fixtures or constructing headers.
Worked example
import { Buffer } from "node:buffer";
console.log([...Buffer.alloc(4, 0xab)]);Result
[ 171, 171, 171, 171 ]Implementation notes
Buffer size counts bytes. A multibyte string used as a fill pattern may be truncated at a byte boundary.
Try it yourself
Inspect zero, a repeated ASCII byte and a value outside one byte's range.
Open the Node.js example →Editorial date January 11, 2026 · Published December 6, 2026