`TextEncoder` converts strings to UTF-8 `Uint8Array` bytes; `TextDecoder` converts them back. Converting bytes to hex requires byte padding.
js
const bytes = new TextEncoder().encode("hello");
const hex = "0x" + Array.from(bytes, b => b.toString(16).padStart(2, "0")).join("");