Creating Constant in Golang

Use Constant for variables that need no updation

Mayank Gupta
TechnoFunnel

--

Creating constant variables in Golang, Passing constant to function

Technofunnel presents another article on declaring constants in Golang, we will discuss about creating Constants in Golang and passing constants to functions. Every language provides capability to add constant and use them in application. Given below is the simple way to create constant is Golang.

In the above code we have created a simple const variable.

  • We cannot use shorthand notation while creating constants
  • We need not to define the type for the constant value.

In the below code, we can see that the shorthand notation does not work with constant values in Golang:

In the below code, we are specifying the type while creating the constant. Which results in error

Passing Constants to Golang Function

As seen in the previous articles, values are sent to function by value. When we are sending parameter to a function, a separate variable is created and the…

--

--

Mayank Gupta
TechnoFunnel

9 Years of Experience with Front-end Technologies and MEAN Stack. Working on all Major UI Frameworks like React, Angular and Vue https://medium.com/technofunnel