Encoding
The TextEncoder takes a stream of code points as input and emits a stream of bytes. Encoding types passed to the constructor are ignored and a UTF-8 TextEncoder is created.
TextEncoder() ↗ returns a newly constructed TextEncoder that generates a byte stream with UTF-8 encoding. TextEncoder takes no parameters and throws no exceptions.
let encoder = new TextEncoder();encoder.encodingDOMString read-only- The name of the encoder as a string describing the method the 
TextEncoderuses (alwaysutf-8). 
- The name of the encoder as a string describing the method the 
 
- 
encode(inputUSVString): Uint8Array- Encodes a string input.
 
 
The TextDecoder interface represents a UTF-8 decoder. Decoders take a stream of bytes as input and emit a stream of code points.
TextDecoder() ↗ returns a newly constructed TextDecoder that generates a code-point stream.
let decoder = new TextDecoder();- 
decoder.encodingDOMString read-only- The name of the decoder that describes the method the 
TextDecoderuses. 
 - The name of the decoder that describes the method the 
 - 
decoder.fatalboolean read-only- Indicates if the error mode is fatal.
 
 - 
decoder.ignoreBOMboolean read-only- Indicates if the byte-order marker is ignored.
 
 
decode(): DOMString- Decodes using the method specified in the 
TextDecoderobject. Learn more at MDN’sTextDecoderdocumentation ↗. 
- Decodes using the method specified in the 
 
Was this helpful?
- Resources
 - API
 - New to Cloudflare?
 - Products
 - Sponsorships
 - Open Source
 
- Support
 - Help Center
 - System Status
 - Compliance
 - GDPR
 
- Company
 - cloudflare.com
 - Our team
 - Careers
 
- 2025 Cloudflare, Inc.
 - Privacy Policy
 - Terms of Use
 - Report Security Issues
 - Trademark