CKTIS / JavaScript
TextDecoder — decoding bytes into text
TextDecoder converts bytes into text. Learn chunked decoding, error handling with fatal, and the meaning of ignoreBOM.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
new TextDecoder()
new TextDecoder("utf-8", { fatal: false, ignoreBOM: false })
decoder.decode(input, { stream: true })
decoder.decode()
decoder.fatal
decoder.ignoreBOMTextDecoder is a WHATWG Encoding API, not a feature of a particular ECMAScript edition. It defaults to UTF-8; an invalid encoding label causes RangeError.
TextDecoder.decode is an instance method: it accepts a buffer or byte view and returns text. { stream: true } retains incomplete sequences between chunks; a final decode() flushes the state.
TextDecoder.fatal and TextDecoder.ignoreBOM denote read-only instance properties. fatal defaults to false: errors produce U+FFFD; true causes TypeError. For UTF-8 and UTF-16, the default ignoreBOM: false removes an initial BOM; true preserves U+FEFF in the result.
Examples
const decoder = new TextDecoder("utf-8", { fatal: true });
const first = decoder.decode(new Uint8Array([0xE2, 0x82]), { stream: true });
const last = decoder.decode(new Uint8Array([0xAC]));
console.log(JSON.stringify([first, last, decoder.decode()]));
console.log(decoder.fatal, decoder.ignoreBOM);Result
["","€",""] true false
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.