Home Blog Programming Using JavaScript ES6 import/export modules

Using JavaScript ES6 import/export modules

Posted on June 8, 2018 by Edit

How to use ES6 modules in your browser

You can include a module in your HTML by adding a script with type="module":

<script type="module">
    import {helloWorld} from './hello-world.js';
    helloWorld();
</script>
const helloWorld = () => alert ('Hello World!');
export {
    helloWorld
};
Download Source

Steps:

  1. Download the source code and unzip the files.
  2. Run a static server on the source folder
    eg: >live-server port=8080
  3. Open the localhost:8080
  4. You would see alert message
Tags : js
This website is made possible by displaying online advertisements to our visitors.
Please consider supporting by disabling your ad blocker.

Get new posts by email:
loading comments...
© 2023 Shivaji Varma. Made in India.