Can someone give me an explanation as to when and why I would use anonymous scope inside a function? (I'm not sure what it's actually called).
I've been given some legacy code to maintain and some of the functions contain this "scope" I have not seen before:
(simplified for demonstration purposes)
func DoSomething(someBoolValue bool) string {
if someBoolValue {
// do some stuff
return "yes"
}
{
// weird scope code
}
return "no"
}
I have created a Go Playground to demonstrate some actual code (that throws an error).