1

If I declare a variable or parameter in a function, does capitalization have any affect or meaning?

Obviously for methods and variables outside of functions it exports them, but what about the above?

user40176
  • 319
  • 2
  • 10

1 Answers1

6

Variables declared inside a function block are always private, or unexported. Capitalization has no effects in this case.

Auyer
  • 2,693
  • 3
  • 15
  • 32
  • To be more precise, it's not that they're unexported - "exporting" a local variable in a function has no meaning (how would you even reference it from outside the function?). This has nothing to do with exporting, but rather with [scoping](https://golang.org/ref/spec#Declarations_and_scope). Only identifiers with package scope can be referenced from outside their scope, and then only if they are exported. – Adrian Oct 24 '19 at 13:15