Node.js · Middle · Question 17 of 75
What is the difference between Buffer.alloc(10) and Buffer.allocUnsafe(10)?
- ✓Correct answer:
allocfills memory with zeros;allocUnsafeis faster but may contain old data from memory - 2
allocUnsafecreates a buffer that can't be resized - 3There is no difference
Explanation
Use allocUnsafe only if you immediately overwrite every byte. Otherwise you might leak sensitive data that was previously in that memory.