Blank operands

September 13, 2023

Don’t you just love the blank identifier? I sure do!

And it the blank identifier can be an operand, too! But with a limitation:

Operands

The blank identifier may appear as an operand only on the left-hand side of an assignment statement.

So this means that

_ = 3

is valid, but

var x = _

Is not.

And I hope it’s pretty obvious why that is the case. What would the value of x be in such an example?

Quotes from The Go Programming Language Specification Version of August 2, 2023

Share this