In the previous lesson, we covered the various data types available in Go. In this lesson, we focus on storing data in variables by exploring variable declaration and syntax. A variable in Go is a named storage location that holds a value. It serves as a reference to that value, forming the backbone of programming logic. Even if the value stored in a variable changes, its name remains constant. Since Go is a statically typed language, each variable must have a data type—either explicitly stated by the programmer or inferred at compile time.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.

var keyword. The general steps involved in variable declaration include:
- Using the
varkeyword. - Specifying the variable name.
- Declaring the variable’s data type.
- Using the assignment operator (
=) to assign a value.
Declaring a String Variable
To declare a string variable, use the following syntax:s is assigned the string value “Hello world”.

Declaring an Integer Variable
Similarly, you can declare an integer variable as shown below:i is of type int and stores the value 100.
Declaring a Boolean Variable
For Boolean values, thebool data type is used. Always write Boolean literals in lowercase:
b with the value false.
Declaring a Float Variable
Go supports two floating-point types:float32 and float64. The following declaration uses float64:
f of type float64 set to the value 77.90.
Variables in Go can also be declared without an initial value. In such cases, Go automatically assigns a zero value based on the type. For example, an uninitialized
int variable gets a value of 0.Running a Simple Example
Below is a complete program that demonstrates variable declaration and usage within themain function. This example uses the fmt package to print a variable’s value.
greeting is assigned the value “Hello World”, which is then displayed in the console.
That concludes the discussion on variable syntax and declaration in Go—an essential concept that underpins building robust Go applications. We’ll see you in the next lesson.