Curriculum Basics Optionals (?T)
Optionals (?T)
TypeScript uses T | null (or T | undefined) to mark "maybe absent" values; Zig's analogue is the type prefix ?T. A ?T value is either some T or null. Three idiomatic ways to handle one: orelse <default> (TS ??), if (x) |unwrapped| { ... } (payload capture that runs only when present), or x.? for "I know it's not null, unwrap anyway" (panics on null). No more silent nullable bugs.
9 ready
01
pick one TypeScript writes T | null (or T | undefined) for "maybe
02
pick one TypeScript's ?? provides a default value when the left side is
03
pick one TypeScript's if (x !== null) narrows the type so the body sees
04
fill blanksFill the missing keyword. The expression provides a fallback
05
fill blanksFill the missing single character that marks an optional type.
06
type one line Type the missing Zig line — declare an optional i32 named
07
type one line Type the missing Zig line — the if (...) header that captures
08
write a programWrite a complete Zig program that:
09
write a program Write a complete Zig program demonstrating the orelse