Curriculum Basics Strings as slices exercise 2 · mcq
Strings as slices
TypeScript reads s.length to get a string's length. Zig's
byte slices have a similar property — but with the same
shortened name as Go and a different type. 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.