Variables in the Go Programming Language(golang)

Assigning a variable

//Variable is declared.
var codingLanguage string
//Variable is assigned.
codingLanguage = "GO"
var codingLanguage string = "golang"
number := 11

Block variables

var sport string = "Football"
var position string = "Quarterback"
var playerName string = "Jimmy Garoppolo"
var playerNumber int = 10
var (
sport string = "Football"
position string = "Quarterback"
playerName string = "Jimmy Garoppolo"
playerNumber int = 10
)

Constants

const randomFact string = "Pteronophobia is the fear of feathers or being tickled by feathers"randomFact = "Bananas are curved because they grow closer to the sun"//This would return an error because we've already declared that the random fact will be and it cannot be overwritten

Shadowing

Converting Datatypes

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Using spring boot in VS Code

Dependency Injection Framework (Unity)

Magneto 2 Community Manifesto

Adobe Commerce Cloud Issues you must know.

Java Libraries

Einstein Next Best Action #TexeiTestsForYou

How to Join Data in Elasticsearch vs Rockset

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sean Dever

Sean Dever

More from Medium

【Go】Implement SHA256, encryption and hashing in Go

Testing Terraform infrastructure as code using Terratest

Generating JSON data from Go (Golang) structs with Go2JSON

Use pprof to view go program stack traces