title: Understanding variable scope in Go
body: <p>I am going through the <code>Go specification</code> to learn the language, and these points are taken from the spec under <a href="https://golang.org/ref/spec#Declarations_and_scope" rel="nofollow noreferrer"><code>Declarations and scope</code></a>.</p>
  
  <p>Though I am able to understand points 1-4, I am confused on points <code>5</code> and <code>6</code>:</p>
  
  <blockquote>
    <ol start="5">
    <li>The scope of a constant or variable identifier declared inside a
    function begins at the end of the ConstSpec or VarSpec (ShortVarDecl
    for short variable declarations) and ends at the end of the
    innermost containing block.</li>
    <li>The scope of a type identifier declared inside a function begins at
    the identifier in the TypeSpec and ends at the end of the innermost
    containing block.</li>
    </ol>
  </blockquote>
  
  <p>This is the code which I used to understand scope in Go:</p>
  
  <pre><code>package main
  
  import "fmt"
  
  func main() {
      x := 42
      fmt.Println(x)
      {
          fmt.Println(x)
          y := "The test message"
          fmt.Println(y)
      }
      // fmt.Println(y) // outside scope of y
  }
  </code></pre>
  
  <p>From this what I understand is <code>scope of x</code> is within the <code>main</code> function, and the <code>scope of y</code> is inside the opening and closing brackets after <code>fmt.Println(x)</code>, and I cannot use <code>y</code> outside of the closing brackets.</p>
  
  <p>If I understand it correctly, both points <code>4 and 5</code> are saying the same thing. So my questions are:</p>
  
  <ol>
  <li><p>If they are saying the same thing, what is the <code>importance</code> of both the
  points?</p></li>
  <li><p>If they are different, can you please let me know the <code>difference</code>?</p></li>
  </ol>