0
0
Node.jsframework~10 mins

Why buffers are needed in Node.js - Test Your Understanding

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

Complete the code to create a buffer of size 10 bytes.

Node.js
const buf = Buffer.[1](10);
Drag options to blanks, or click blank then click option'
Aalloc
Bfrom
Cnew
Dcreate
Attempts:
3 left
💡 Hint
Common Mistakes
Using Buffer.from instead of Buffer.alloc
Trying to use 'new Buffer' which is deprecated
2fill in blank
medium

Complete the code to convert a string to a buffer.

Node.js
const buf = Buffer.[1]('hello');
Drag options to blanks, or click blank then click option'
Afrom
Balloc
Cnew
Dcreate
Attempts:
3 left
💡 Hint
Common Mistakes
Using Buffer.alloc instead of Buffer.from
Trying to use 'new Buffer' which is deprecated
3fill in blank
hard

Fix the error in the code to correctly create a buffer from an array.

Node.js
const buf = Buffer.[1]([1, 2, 3]);
Drag options to blanks, or click blank then click option'
Aalloc
Bcreate
Cfrom
Dnew
Attempts:
3 left
💡 Hint
Common Mistakes
Using Buffer.alloc which creates empty buffer
Using 'new Buffer' which is deprecated
4fill in blank
hard

Fill both blanks to create a buffer from a string and specify UTF-8 encoding.

Node.js
const buf = Buffer.[1]('hello', [2]);
Drag options to blanks, or click blank then click option'
Afrom
B'utf8'
C'ascii'
Dalloc
Attempts:
3 left
💡 Hint
Common Mistakes
Using Buffer.alloc instead of Buffer.from
Using wrong encoding like 'ascii' when UTF-8 is intended
5fill in blank
hard

Fill all three blanks to create a buffer from a string, specify encoding, and convert it back to string.

Node.js
const buf = Buffer.[1]('hello', [2]);
const str = buf.toString([3]);
Drag options to blanks, or click blank then click option'
Afrom
B'utf8'
Dalloc
Attempts:
3 left
💡 Hint
Common Mistakes
Using Buffer.alloc instead of Buffer.from
Using different encodings for creation and conversion