0
0
Node.jsframework~10 mins

Buffer concatenation in Node.js - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a Buffer from a string.

Node.js
const buf = Buffer.[1]('hello');
Drag options to blanks, or click blank then click option'
Afrom
Balloc
Cconcat
Dslice
Attempts:
3 left
💡 Hint
Common Mistakes
Using Buffer.alloc instead of Buffer.from
Trying to use Buffer.concat to create a single buffer
2fill in blank
medium

Complete the code to concatenate two Buffers.

Node.js
const combined = Buffer.[1]([buf1, buf2]);
Drag options to blanks, or click blank then click option'
Aconcat
Bcopy
Calloc
Dfrom
Attempts:
3 left
💡 Hint
Common Mistakes
Using Buffer.from instead of Buffer.concat
Trying to use Buffer.alloc to join buffers
3fill in blank
hard

Fix the error in the code to concatenate buffers with a total length.

Node.js
const combined = Buffer.concat([bufA, bufB], [1]);
Drag options to blanks, or click blank then click option'
AbufA + bufB
BbufA.length + bufB.length
CbufA.size + bufB.size
DbufA.length * bufB.length
Attempts:
3 left
💡 Hint
Common Mistakes
Using bufA + bufB which concatenates objects incorrectly
Using bufA.size which is undefined
4fill in blank
hard

Fill both blanks to create two buffers and concatenate them.

Node.js
const buf1 = Buffer.[1]('Node');
const buf2 = Buffer.[2]('JS');
const result = Buffer.concat([buf1, buf2]);
Drag options to blanks, or click blank then click option'
Afrom
Balloc
DallocUnsafe
Attempts:
3 left
💡 Hint
Common Mistakes
Using Buffer.alloc which creates empty buffers
Mixing different buffer creation methods
5fill in blank
hard

Fill all three blanks to create buffers, concatenate, and convert to string.

Node.js
const bufA = Buffer.[1]('Hello, ');
const bufB = Buffer.[2]('World!');
const combined = Buffer.[3]([bufA, bufB]);
console.log(combined.toString());
Drag options to blanks, or click blank then click option'
Afrom
Cconcat
Dalloc
Attempts:
3 left
💡 Hint
Common Mistakes
Using Buffer.alloc which creates empty buffers
Trying to call toString() on buffers before concatenation