Specifically, this part from the #Defer_statements linked by Peter:
"For instance, if the deferred function is a function literal and the surrounding function has named result parameters that are in scope within the literal, the deferred function may access and modify the result parameters before they are returned."
In the case of `test`, the x variable is a named return variable so the defer is able to modify the returned value after the `return` but before the caller receives the result.
In the case of `anotherTest`, the x variable is a local variable; when the `return x` is executed, the value of `x` is effectively copied into a new location that is distinct from the `x` variable, so the defer is modifying a different value than the one that is actually being returned.
As a third example, note that you can also return a value directly even when using named return variables, which will immediately set the return variables to the values in the return statement before defers are executed:
https://play.golang.com/p/JduT2zD5Nah