typeover
curriculum

Curriculum Foundations Strings, bytes, runes exercise 3 · mcq

Strings, bytes, runes

Iterating over a string in TypeScript with for...of gives you one character at a time, regardless of whether each character is one byte or several (TS handles UTF-16 internally). Go's range over a string gives you something different — pick the line that matches the TS semantics.

TypeScript reference
Pick the idiomatic Go translation

About this theme

Go strings are immutable byte sequences. There are no template literals — fmt.Sprintf does the job. A byte is an alias for uint8; a rune is int32 and represents a Unicode codepoint. When you range over a string, you get runes (codepoints), not bytes. This matters more than it sounds.