JS Built-ins
TextDecoderintermediate

TextDecoder.decode β€” round-trip 'hello'

πŸ“– Usage Example
const bytes = new Uint8Array([72, 101, 108, 108, 111])
new TextDecoder().decode(bytes)  // β†’ 'Hello'

decode() converts a buffer of bytes into a JavaScript string.

decode() Round-trip

Encoding a string with TextEncoder and then decoding with TextDecoder should return the original string.

Challenge: Verify that new TextDecoder().decode(new TextEncoder().encode('hello')) === 'hello'.

πŸ’‘ Hints (1)
  • β€’ TextEncoder and TextDecoder are inverse operations for valid UTF-8.