// 📁 sayHi.js
export function sayHi(user) {
  alert(`Hello, ${user}!`);
}
// 📁 say.js
function sayHi(user) {
  alert(`Hello, ${user}!`);
}

function sayBye(user) {
  alert(`Bye, ${user}!`);
}

export {sayHi, sayBye}; // a list of exported variables
// 📁 main.js
import { sayHi, sayBye } from './say.js';
sayHi('John'); // Hello, John!
sayBye('John'); // Bye, John!
// 📁 main.js
import * as say from './say.js';
say.sayHi('John');
say.sayBye('John');
<script type="module">
  import {sayHi} from './say.js';
  document.body.innerHTML = sayHi('John');
</script>

export as

// 📁 say.js
export {sayHi as hi, sayBye as bye};

import as

// 📁 main.js
import { sayHi as hi, sayBye as bye } from './say.js';
hi('John'); // Hello, John!
bye('John'); // Bye, John!

export default

  1. Put export default before the “main export” of the module.