Web APIs

TextDecoder.prototype.decode()

Try the free JavaScript compiler

Decodes a byte source; fatal mode rejects malformed input with TypeError.

Formal Syntax & Structure

javascript syntaxjavascript
decoder.decode(input, options)

Parameters & Attributes

NameTypeDescription
inputBufferSourceOptional encoded data.
optionsobjectOptional stream flag.

Return Value

string

Decodes a byte source; fatal mode rejects malformed input with TypeError.

Working Example

Example Snippetjavascript
(async () => {const b=new Uint8Array([255]);const d=new TextDecoder();let err;try{new TextDecoder("utf-8",{fatal:true}).decode(b);}catch(e){err=e.name;}console.log(d.decode(b).codePointAt(0),err);})()
JavaScript Reference