title: Variable scope in JavaScript , Hoisting, Execution context
body: <p>I am a beginner for javascript, and I encountered something weird when I was trying to understand variable-scope.
  here is the code I wrote:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var year = 2020
  
  function someFunction(){
      console.log(year) 
  }
  someFunction()</code></pre>
  </div>
  </div>
  
  and the output was: 2020</p>
  
  <p>but then I redeclared the variable "year" again inside the function but after the console.log() statement
  like this :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var year = 2020
  
  function someFunction(){
      
      console.log(year) 
      var year = 1999
  }
  someFunction()</code></pre>
  </div>
  </div>
  </p>
  
  <p>and the output I got was: undefined</p>
  
  <p>As a beginner, I found this hard to understand why . I hope you can help me.
  Thanks!</p>