title: Safari can't find global const variable used in function (Can't find variable error)
body: <p>JavaScript in Safari fails and execution is stopped if <code>const</code> is used within <code>function</code>. All other browsers (Chrome, Firefox, ...) work correctly, even on macOS.</p>
  <p>My code (simplified):</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 a = 1;
  
  function f() {
    console.log(a);
  }
  f();</code></pre>
  </div>
  </div>
  </p>
  <p>In JavaScript console I can see:
  <code>[Error] ReferenceError: Can't find variable: a</code></p>
  <p>I resolved it by changing <code>const</code> to <code>var</code> and it started to work immediately. (I didn't try <code>let</code>).</p>
  <pre class="lang-js prettyprint-override"><code>    var a = 1;
      function f() {
        console.log(a);
      }
      f();
  </code></pre>
  <p>I tried to investigate and understand why this is a problem. However, none of the resources gave me an answer why <code>const</code> should not work within <code>function</code>:</p>
  <ul>
  <li><a href="https://www.w3schools.com/js/js_const.asp" rel="nofollow noreferrer">JavaScript Const</a></li>
  <li><a href="https://www.w3schools.com/js/js_scope.asp" rel="nofollow noreferrer">JavaScript Scope</a></li>
  </ul>
  <p>Is it something to do with Safari (security?) settings?</p>
  <p>Unfortunately, I can't troubleshoot this further as I'm working on Windows and don't have macOS available all the time.</p>