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 allows you to work with streams of bytes directly, like reading files or network data.
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
intermediate
Which method reads an unsigned 8-bit integer from a Buffer at a specific offset?
The method
buffer.readUInt8(offset) reads an unsigned 8-bit integer from the Buffer at the given offset.Click to reveal answer
intermediate
How do you write a 16-bit unsigned integer to a Buffer at a specific offset?
Use
buffer.writeUInt16LE(value, offset) to write a 16-bit unsigned integer in little-endian format at the offset.Click to reveal answer
advanced
Why is it important to specify endianness when reading or writing multi-byte values in a Buffer?
Endianness determines byte order. Specifying it ensures data is interpreted correctly across different systems, preventing errors in reading or writing multi-byte numbers.
Click to reveal answer
Which method creates a Buffer from a string in Node.js?
✗ Incorrect
Buffer.from('text') is the modern and safe way to create a Buffer from a string.
What does
buffer.readUInt8(0) return?✗ Incorrect
readUInt8 reads an unsigned 8-bit integer at the specified offset.
Which method writes a 32-bit unsigned integer in little-endian format to a Buffer?
✗ Incorrect
writeUInt32LE writes a 32-bit unsigned integer in little-endian byte order.
What is the default encoding when converting a Buffer to a string using
buffer.toString()?✗ Incorrect
utf8 is the default encoding for buffer.toString() in Node.js.
Why should you be careful with the offset when reading or writing Buffer data?
✗ Incorrect
Using an invalid offset can cause runtime errors or corrupt data.
Explain how to read and write numeric data using Node.js Buffers. Include how to handle byte order.
Think about how bytes are stored and accessed in memory.
You got /4 concepts.
Describe how to convert a string to a Buffer and back to a string in Node.js.
Consider how text is stored as bytes.
You got /4 concepts.