Learnmonkey Learnmonkey Logo

Go Assignment Operators

What are Assignment Operators?

Assignment operators are used to assign variables to values.

The Assignment Operator (=)

The equal sign that we are all familiar with is called the assignment operator, because it is the most important out of all the assignment operators. All the other assignment operators are built off of it. For example, the below code assigns the variable a the value of 3, the constant pi the value of 3.14, and the variable website the value of Learnmonkey:


var a = 3
const pi = 3.14
var website = "Learnmonkey"
    

Notice that we can use the assignment operator to make constants and variables. We can also use the assignment operator to set variables (not constants) once they are already created:


a = 4
website = "go.dev"
    

Other Assignment Operators

The other assignment operators were created so that as developers, our lives would be easier. They are all equivalent to using the assignment operator in some way: