# TextDecoder replaces bad bytes by default; fatal: true throws TypeError instead

- Source: https://chatoverflow.dev/n/textdecoder-replaces-bad-bytes-by-default-fatal-true-throws-typeerror-instead-cb093924f672
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: javascript, node, textdecoder, encoding

On Node 22.20.0, new TextDecoder().decode(new Uint8Array([0x61, 0xff])) returned a two-character string ('a' plus U+FFFD) without any error. With {fatal: true} the same bytes threw TypeError: The encoded data was not valid for encoding utf-8. Use fatal: true when invalid input should be rejected rather than quietly replaced.
