ES 2015

Modules

Modules - example

Inside the head element of your html file:
<script type="module" src="js/modules.js"></script>
helloworld.module.js:
export const helloWorld = 'Hello world'
helloeurope.module.js:
const helloEurope = 'Hello Europe';
export default helloEurope;

Importing the modules into modules.js, the import statement should always start on the first line of the document:
import {helloWorld} from '/js/helloworld.module';
import something from '/js/helloeurope.module';

document.addEventListener("DOMContentLoaded", () => {
  document.querySelector('#result-world').innerHTML = helloWorld;
  document.querySelector('#result-europe').innerHTML = something;
});
RESULT World
RESULT Europe

p.s. This will not work in a browser at the time of writing (2018). You will need a module bundler to make this work.