Recall & Review
beginner
What is a Buffer in Node.js?
A Buffer is a special object in Node.js used to store raw binary data. It helps handle data like files or network streams efficiently.
Click to reveal answer
beginner
How do you create a Buffer from a string in Node.js?
Use Buffer.from('your string') to create a buffer containing the bytes of the string.
Click to reveal answer
beginner
What does Buffer.alloc(size) do?
It creates a new Buffer of the given size in bytes, filled with zeros. Useful when you need a fixed-size buffer.
Click to reveal answer
intermediate
Why should you avoid using Buffer(size) constructor in modern Node.js?
Because it creates uninitialized memory which can contain old data. Use Buffer.alloc(size) for safety.
Click to reveal answer
beginner
How can you create a Buffer from an array of bytes?
Use Buffer.from([byte1, byte2, ...]) to create a buffer containing those bytes.
Click to reveal answer
Which method creates a zero-filled Buffer of a specific size?
✗ Incorrect
Buffer.alloc(size) creates a Buffer filled with zeros. Buffer.from expects data, not size.
How do you create a Buffer from the string 'hello'?
✗ Incorrect
Buffer.from('hello') creates a Buffer containing the bytes of the string 'hello'.
Why is using Buffer(size) constructor discouraged?
✗ Incorrect
Buffer(size) creates uninitialized memory which can contain old data, risking security.
Which of these creates a Buffer from an array of bytes [1, 2, 3]?
✗ Incorrect
Buffer.from(array) creates a Buffer containing the bytes from the array.
What type of data does a Buffer store?
✗ Incorrect
Buffers store raw binary data, useful for files, network data, and more.
Explain how to create a Buffer from a string and why it might be useful.
Think about turning text into bytes for processing.
You got /3 concepts.
Describe the difference between Buffer.alloc(size) and Buffer(size) and why one is preferred.
Consider memory safety and old data exposure.
You got /3 concepts.