title: Conditionally initializing a constant in Javascript
body: <p>ES6 onwards we have <code>const</code>.</p>
  
  <p>This is not allowed:</p>
  
  <pre><code>const x; //declare first
  //and then initialize it
  if(condition) x = 5;
  else x = 10;
  </code></pre>
  
  <p>This makes sense because it prevents us from using the constant before it's initialized.</p>
  
  <p>But if I do</p>
  
  <pre><code>if(condition)
      const x = 5;
  
  else 
      const x = 10;
  </code></pre>
  
  <p>x becomes block scoped.</p>
  
  <p>So how to conditionally create a constant?</p>