What Are Go Keywords and Reserved Words

Go keywords are 25 reserved words like func, var, and if that define syntax and cannot be used as identifiers.

Go keywords are reserved words that define the language's syntax and cannot be used as identifiers like variable or function names. There are 25 keywords in Go, including func, var, if, else, for, struct, interface, type, package, import, return, break, continue, goto, defer, fallthrough, range, select, case, default, switch, chan, map, const, and true/false/nil (which are predeclared identifiers but act similarly). Using any of these as a name will result in a syntax error.

// Valid usage
func main() {
    var x int
    if x == 0 {
        return
    }
}

// Invalid usage: 'func' is a keyword
// var func int // Syntax error: expected 'IDENT', found 'func'