Try the inputs from this article
Run the example or change the input to compare results. Tool functions and standard browser APIs calculate the results in your browser.
Run example
Changing the input clears the previous result.
Download result JSONThese are illustrative inputs. Result field names are code identifiers; see the article for units and conditions.
A file can include EF BB BF
Unicode documents EF BB BF as the UTF-8 BOM. In UTF-8 it acts as an encoding signature, not a byte-order switch. Our six-byte file combines those three bytes with abc’s 61 62 63. Moyoutil’s file mode reads original bytes with arrayBuffer; text mode encodes the string as UTF-8 with TextEncoder.
ignoreBOM: true retains the character
By default, TextDecoder omits an initial BOM from the output string. This input produces abc. Setting ignoreBOM to true bypasses BOM handling, leaving U+FEFF in the string. Re-encoding the default output gives three bytes; its SHA-256 differs from the six-byte original in this example. Do not assume every editor or copying process behaves this way.
const bytes = Uint8Array.of(0xEF, 0xBB, 0xBF, 0x61, 0x62, 0x63);
new TextDecoder().decode(bytes) === "abc" // true
new TextDecoder("utf-8", {ignoreBOM: true})
.decode(bytes) === "\uFEFFabc" // true
new TextEncoder().encode(new TextDecoder().decode(bytes)).length // 3To compare an original file’s checksum, use Moyoutil’s file mode. Pasting the visible abc hashes a different input. If U+FEFF remains in the string, text encoding includes its bytes. Do not remove the original BOM just to match a checksum; check the reference algorithm and file version.
new TextDecoder().decode(Uint8Array.of(0x61, 0xEF, 0xBB, 0xBF))
=== "a\uFEFF" // trueFrequently Asked Questions
Does it also remove U+FEFF in the middle?
This TextDecoder example omits only the initial BOM. An internal U+FEFF remains; ignoreBOM: true also retains the initial character. We executed the code below and empty input to check these boundaries.