OneBite.Dev - Coding blog in a bite size

create a variable in Go

Code snippet on how to create a variable in Go

  var name string = "John Doe"

This code is creating a variable named “name” of type string and assigning the value of “John Doe” to it. As all variables, it needs to have a type associated with it. In this case, it is a string. The ”=” is used to assign a value to a variable. In this case, the value being assigned is “John Doe”. Once declared, the variable will be accessible for the rest of the program.

go