Variables and constants
Variables are spaces in computer's memory to store values that can be modified during the execution of the program. Variables and constants have a type like the ones described in preceding text. Although, you don't need to explicitly write the type of them (although you can do it). This property to avoid explicit type declaration is what is called Inferred types. For example:
//Explicitly declaring a "string" variable var explicit string = "Hello, I'm a explicitly declared variable"
Here we are declaring a variable (with the keyword var
) called explicit
of string type. At the same time, we are defining the value to Hello World!
.
//Implicitly declaring a "string". Type inferred inferred := ", I'm an inferred variable "
But here we are doing exactly the same thing. We have avoided the var
keyword and the string
type declaration. Internally, Go's compiler will infer (guess) the type of the variable to a string type. This way you have...