Complete the code to create a buffer of size 10 bytes.
const buf = Buffer.[1](10);
The Buffer.alloc(size) method creates a new buffer of the specified size filled with zeros.
Complete the code to create a buffer from the string 'hello'.
const buf = Buffer.[1]('hello');
The Buffer.from(string) method creates a new buffer containing the bytes of the given string.
Fix the error in the code to create a buffer from an array of bytes.
const buf = Buffer.[1]([1, 2, 3, 4]);
To create a buffer from an array of bytes, use Buffer.from(array). Buffer.alloc only allocates empty buffers.
Fill both blanks to create a buffer of size 5 and fill it with the byte value 255.
const buf = Buffer.[1](5, [2]);
Buffer.alloc(size, fill) creates a buffer of the given size and fills it with the specified byte value.
Fill all three blanks to create a buffer from the string 'abc', specify UTF-8 encoding, and slice the first two bytes.
const buf = Buffer.[1]('abc', [2]).[3](0, 2);
Buffer.from(string, encoding) creates a buffer from a string with specified encoding. slice(start, end) extracts part of the buffer.