← BYTES
Go·Starter·Ref: 10.1.13

What does the defer keyword do when placed before a function call?

Have a question about this video? Mention reference 10.1.13 when you contact us.

a.It cancels the function call entirely unless a condition is met
b.It schedules that function call to run just before the surrounding function returns, regardless of how it returns
c.It runs the function call immediately, but silently ignores its return value
d.It makes the function call execute on a separate goroutine concurrently
defer postpones execution of the given call until the enclosing function is about to return -- commonly used for cleanup like defer file.Close() right after a successful file.Open(), guaranteeing the close runs on every exit path (normal return, early return, or even a panic) without needing to repeat the cleanup call at each one.

Find this on YouTube & Instagram

Every BYTES video is tagged with its reference number and topic — search any of these on YouTube or Instagram to find this one:

#BYTES#BYTES10113#Go