Oluwaseun Dabiri

Oluwaseun Dabiri

My Go lang Journey - Variable and Constants Declaration in Go.

My Go lang Journey - Variable and Constants Declaration in Go.

Subscribe to my newsletter and never miss my upcoming articles

So I started learning Go lang about a week now, in this article I will be discussing variables and constants declarations in Go.

Firstly what is Go? Go is a programming language produced by Google. With a simple grammar, it's easy to learn and well-suited for team development. Another characteristic is its speed. It's also a language that's growing in popularity; used by everyone from startups, where development speed is important, to large scale system development.

What are variables? You can think of a variable as a box where you can store a value. Also, the box (variable) has a name which can be used to retrieve a value from the variable anytime. Variables are needed for almost any program, so it's important to understand how to use them.

you can declare a variable by using the var keyword, variable name, the datatype and using the assignment operator (=) to assign a value or expression.

dabsclement (1).png

also, there is a shorthand way of declaring variables in Go. The := syntax is shorthand for declaring and initializing a variable.

shorthand.png

Declaring Constants. The keyword const is used to declare a constant, the term constant in Go is used to denote fixed values.

dabsclement (3).png When a constant is declared another value cannot be reassigned to the const again with the program dabsclement (4).png

The above is my little interaction with using variables and constants in Go lang. Please share your valuable feedback and comments.

 
Share this