Syntax

Go Declare a Variable Syntax

In Go, declare a variable: declares with var or the short := form — var n int = 1 name := "Ada"

Quick Answer

Syntax
var n int = 1 name := "Ada"
GoSyntax

Declare a Variable

Code example
var n int = 1 name := "Ada"

Declares with var or the short := form.

Learn More

How to declare a variable in Go

  1. Open your Go file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Go Declare a Variable Syntax

Use var n int = 1 name := "Ada".

Related Syntax References

Frequently asked questions

What is the Go syntax for declare a variable?

Use this pattern: var n int = 1 name := "Ada"

Can I copy this Go code example?

Yes. Use Copy code and adapt the example to your program.

Is this Go syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify