Why Do We Call It TextEncoder and TextDecoder?

May 5, 2025 2 answers
Asked by semitone
I've been puzzled about the naming of TextEncoder and TextDecoder in JavaScript. It feels like they should be switched around because a TextEncoder converts a stream of code points into a byte stream, which seems like it should be called 'decoding' since it's taking encoded data and producing output. Can anyone shed light on the reasoning behind these names? Also, I'm curious if there are any resources on the history of these naming decisions.

Answers

ferry.wake
It might just be a matter of perspective. To me, TextEncoder makes sense because it encodes text into bytes, which is pretty intuitive. But hey, maybe you could grab a beer for whoever named it and ask them yourself! 😂
Reply to this answer
dinner is negotiable
The naming actually follows a consistent pattern that's seen in many media encoders. You take some text or media and encode it into bytes, then when you decode, you're going back from bytes to that original format. It gets tricky because different platforms might represent strings differently, but nonetheless, it's about encoding and decoding according to chosen formats, not just raw code points.

public library card: I like how you clarified that. Your explanation is much clearer than mine!

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions