typeover
curriculum

Curriculum Basics Conditionals (if and switch) exercise 3 · mcq

Conditionals (if and switch)

Here's where Zig diverges from TypeScript: Zig's switch is an EXPRESSION, not a statement. It evaluates to a value you can assign or return directly — like a ternary scaled up. Pick the idiomatic Zig translation.

TypeScript reference
Pick the idiomatic Go translation

About this theme

Zig's if looks like TypeScript's: parens around the condition, optional braces around the body. The catch: Zig has no truthy values — the condition must be bool. switch is an expression in Zig (not a statement), so it can be assigned directly. The TS reflex matches Zig here more cleanly than it matches Go.