What is the purpose of the 'defer' keyword in Go?
- Defer is used to declare global variables.
- Defer is used to delay the execution of a statement until the surrounding function returns.
- Defer is used to force a function to terminate.
- Defer is used to handle panics in Go.
The 'defer' keyword in Go allows postponing the execution of a function call until the surrounding function returns. It's commonly used for cleanup activities or closing resources after a function exits.
Loading...
Related Quiz
- Which interface in the database/sql package is used to represent a database row?
- You are designing a system where a function needs to accept an arbitrary number of arguments and process them. Which type of function would you use?
- In Go, a custom error can be created by implementing the _____ interface.
- Describe a scenario where you would need to create custom middleware in the Echo framework and explain how you would implement it.
- How does Go determine if two maps are equal?