Web APIs
TextDecoder.prototype.decode()
Decodes a byte source; fatal mode rejects malformed input with TypeError.
Formal Syntax & Structure
javascript syntaxjavascript
decoder.decode(input, options)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| input | BufferSource | Optional encoded data. |
| options | object | Optional 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);})()