typeover
curriculum

Curriculum Idioms & ecosystem Defer exercise 1 · mcq

Defer

defer schedules a function call to run when the enclosing function returns. Pick the line that defers a call to cleanup(). TypeScript: try { ... } finally { cleanup(); } — same idea, no extra indentation in Go.

TypeScript reference
Pick the idiomatic Go translation

About this theme

defer fn() schedules fn to run when the surrounding function returns. The closest TS analogue is a try/finally you don't have to indent. Multiple defers run LIFO. Arguments are evaluated at the defer site, not at the call site — a common surprise. Also: defer in a loop accumulates.