Golang Variables

Golang Variables

ยท

1 min read

Hello World ๐Ÿ˜

So , Today I learned about Golang Variables and found it amazing ๐Ÿฅณ

Welcome to my blog!

Let Learn about this ๐Ÿ‘‡

What is Variable ? ๐Ÿง A variable is a storage location, with a specific type and an associated name. Let's change the program we wrote in chapter 2 so that it uses a variable:

We can decalare variable in 2 ways ๐Ÿ˜Ž

First Way ๐Ÿ˜ฑ

package main

import "fmt"

func main() {
  var x string = "Hello World"
  fmt.Println(x)
}

Second Way๐Ÿคฉ

package main

import "fmt"

func main() {
x := "Hello World"
fmt.Println(x)
}

Done ! ๐Ÿ˜†

joking-kidding.gif

Okay , So now take a look here ๐Ÿ‘‡

How to Name a Variable ? ๐Ÿง

Naming a variable properly is an important part of software development. Names must start with a letter and may contain letters, numbers or the _ (underscore) symbol. The Go compiler doesn't care what you name a variable so the name is meant for your (and others) benefit. ๐Ÿฅฑ

name := "Max"
fmt.Println("My dog's name is", name)

I will explain the scopes in next blog . Find me on Twitter ๐Ÿ‘€

Stay Tuned ! ๐Ÿคญ

ย