0
0
Node.jsframework~5 mins

Creating buffers in Node.js - Quick Revision & Summary

Choose your learning style9 modes available
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?
ABuffer.create(size)
BBuffer.from(size)
CBuffer.alloc(size)
DBuffer.new(size)
How do you create a Buffer from the string 'hello'?
ABuffer.from('hello')
Bnew Buffer('hello')
CBuffer.alloc('hello')
DBuffer.create('hello')
Why is using Buffer(size) constructor discouraged?
AIt is slower than Buffer.alloc
BIt creates uninitialized memory which may contain sensitive data
CIt does not create a Buffer
DIt only works with strings
Which of these creates a Buffer from an array of bytes [1, 2, 3]?
ABuffer.from([1,2,3])
BBuffer.alloc([1,2,3])
CBuffer.new([1,2,3])
DBuffer.create([1,2,3])
What type of data does a Buffer store?
AOnly numbers
BText only
CJavaScript objects
DRaw binary data
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.