title: Chrome console already declared variables throw undefined reference errors for let
body: <p>Recently I ran into this weird thing in chrome console. Here I am intentionally assigning an undefined thing to a in order to throw an error.</p>
  
  <pre><code>let a = werwr // Uncaught ReferenceError: werwr is not defined
  </code></pre>
  
  <p>Then when I tried to assign something legit to a, this happened:</p>
  
  <pre><code>let a = "legit string"   // Uncaught SyntaxError: Identifier 'a' has already been declared
  </code></pre>
  
  <p>so I can't use "let" because a has already been declared. So I tried to reassign something else to the "already declared a"</p>
  
  <pre><code>a = "legit string"   //  Uncaught ReferenceError: a is not defined
  </code></pre>
  
  <p>So it seems like I can't reassign something else to a but at the same time, a has been declared so I can't use let again. </p>
  
  <p>I understand the difference between declaring and assigning a variable. However here it seems that neither could be done again. Does this has something to do with the scope of "let" in console? Because the same thing totally works for "var"</p>
  
  <pre><code>var a = werwr 
  // Uncaught ReferenceError: werwr is not defined
  
  a = ”legit string“  
  // ”legit string“
  
  var a = "legit string" 
  // Uncaught SyntaxError: Identifier 'a' has already been declared
  </code></pre>
  
  <p><strong>Follow-up</strong></p>
  
  <p>There seem to be some difference between "manually" hoisting the let statement vs the implicit case.</p>
  
  <pre><code>throw new Error
  let example = 5
  // same errors as before
  </code></pre>
  
  <p>while in this case example can be reassigned again.</p>
  
  <pre><code>let example
  throw new Error
  example = 5
  </code></pre>