Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

node
node.js

What is Buffer.isEncoding() in Node.js?

Ayesha Naeem

The Buffer.isEncoding() function tests if an encoding format is supported or not.

Prototype

Parameter and return value

The Buffer.isEncoding() function accepts the encoding format as a single parameter of type string.

The Buffer.isEncoding() function returns true if the encoding format is supported; otherwise, it returns false.

Examples

The following code demonstrates how to use the Buffer.isEncoding() function in Node.js.

console.log(Buffer.isEncoding('base64'));

console.log(Buffer.isEncoding('hex'));

console.log(Buffer.isEncoding('utf8'));

console.log(Buffer.isEncoding('ucs2'));

console.log(Buffer.isEncoding('binary'));

console.log(Buffer.isEncoding('utf/8'));

console.log(Buffer.isEncoding('randomencoding'));

The above example illustrates that some of the supported encoding formats are base64, hex, utf8, ucs2, and binary.

RELATED TAGS

node
node.js

CONTRIBUTOR

Ayesha Naeem
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring