title: How to do import/export a class in Vanilla JavaScript (JS)
body: <p>I'm using Vanilla JavaScript (JS) and trying to leverage the concept of <code>class</code> and <code>module</code> import/export which came as part of ECMA-2015(ECMA-6) release.</p>
  <p>Please see the code snippet below:</p>
  <p><code>rectangle.js</code> file -</p>
  <pre><code>export default class  Rectangle{
    constructor(height, width) {
      this.height = height;
      this.width = width;
    }
  }
  </code></pre>
  <p><code>myHifiRectangle.js</code> file -</p>
  <pre><code>import Rectangle from 'rectangle.js';
  
  class MyHiFiRectangle extends Rectangle {
    constructor(height, width) {
        super(height,width);
        this.foo= &quot;bar&quot;;  
   }
  }
  </code></pre>
  <p>I'm trying to use above *.js files in an HTML web page <code>test.html</code> as shown below:</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-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang = "en"&gt;
     &lt;head&gt;
        &lt;meta charset = "UTF-8"&gt;
        &lt;title&gt;Javascipt by Rasik Bihari Tiwari&lt;/title&gt;
         &lt;script src="Scripts/rectangle.js"&gt;&lt;/script&gt;
         &lt;script src="Scripts/myHiFiRectangle.js"&gt;&lt;/script&gt;
        &lt;script type="text/javascript"&gt;
      
     var v = new MyHiFiRectangle(2,4);
     console.debug(v.foo);
        &lt;/script&gt;
     &lt;/head&gt;
     &lt;body &gt;
  
     &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>Then, I tried browsing <code>test.html</code> file in browser. Result of browsing for of the browsers is as below:</p>
  <p>On Google Chrome I get below error:</p>
  <blockquote>
  <p>Uncaught SyntaxError: Unexpected token export</p>
  </blockquote>
  <p>On Mozilla firefox I get below error:</p>
  <blockquote>
  <p>SyntaxError: export declarations may only appear at top level of a
  module</p>
  <p>SyntaxError: import declarations may only appear at top level
  of a module</p>
  <p>ReferenceError: MyHiFiRectangle is not defined[Learn More]</p>
  </blockquote>
  <p>I tried reordering the JS files which are referred in the head tag of the HTML file but it makes no difference.</p>
  <p><strong>P.S.</strong> I'm not using any transpilers like Babel. I'm trying to see the working of native support of <code>class</code> and <code>module</code> export/import construct in JS (ECMA-2015 release aka ECMA-6) and how it works.</p>