Curriculum Basics Strings as slices exercise 3 · mcq
Strings as slices
TypeScript's s.slice(start, end) returns a substring. Zig
has a simpler form: s[start..end] returns another []const
u8 viewing the same bytes. No method call, no copy. Pick
the Zig translation.
TypeScript reference
About this theme
There's no String type in Zig. String literals are byte slices typed as []const u8 — same shape as any other slice of read-only bytes. Length comes from .len (a usize), indexing returns a single u8 byte, and substring with s[a..b] produces another []const u8. The mental model from TypeScript needs one shift: a Zig string isn't a value-typed character sequence, it's a view into bytes.