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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *