title: javascript fundamentals - temporal dead zone, hoisting or closure
body: <p>why does this code work  </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>const btn = document.getElementById("btn");
  
  btn.onclick = function() {
    printMe(obj);
  };
  
  function printMe(person) {
    console.log(person.firstName, person.lastName);
  }
  
  const obj = {
    firstName: "John",
    lastName: "Wick"
  };</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;button id="btn"&gt;Click me!&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>and/but this does not (temporal dead zone I know)</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>printMe(obj);
  
  function printMe(person) {
    console.log(person.firstName, person.lastName);
  }
  
  const obj = {
    firstName: "John",
    lastName: "Wick"
  };</code></pre>
  </div>
  </div>
  </p>
  
  <p>does it have something to do with hoisting?
  please recommend further reading on this topic.</p>