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 packets before converting them to strings or other formats.
Click to reveal answer
beginner
How do you convert a Buffer to a string in Node.js?
Use the
toString() method on the Buffer object. For example: buffer.toString() converts the buffer's binary data into a readable string.Click to reveal answer
beginner
What encoding does
buffer.toString() use by default?By default,
buffer.toString() uses UTF-8 encoding to convert the binary data into a string.Click to reveal answer
intermediate
How can you convert only part of a Buffer to a string?
You can pass start and end positions to
toString(), like buffer.toString('utf8', start, end). This converts only the bytes between start and end to a string.Click to reveal answer
intermediate
Why might you need to specify encoding when converting a Buffer to a string?
Different data might use different encodings like UTF-8, ASCII, or Base64. Specifying encoding ensures the Buffer converts correctly to the intended string format.
Click to reveal answer
What method converts a Node.js Buffer to a string?
✗ Incorrect
The
toString() method converts a Buffer's binary data into a string.What is the default encoding used by
buffer.toString()?✗ Incorrect
UTF-8 is the default encoding for
buffer.toString().How do you convert only a part of a Buffer to a string?
✗ Incorrect
You specify encoding and byte positions like
buffer.toString('utf8', start, end) to convert part of a Buffer.Which of these is NOT a valid encoding option for Buffer to string conversion?
✗ Incorrect
'json' is not a valid encoding for Buffer conversion; common encodings include 'utf8', 'ascii', and 'binary'.
Why might you convert a Buffer to a string in Node.js?
✗ Incorrect
Converting a Buffer to a string lets you read or display the binary data as text.
Explain how to convert a Node.js Buffer to a string and why encoding matters.
Think about how raw data becomes readable text.
You got /4 concepts.
Describe how to convert only a part of a Buffer to a string in Node.js.
Partial conversion helps when you want a slice of data.
You got /3 concepts.