importing functions javascript code example
Example 1: alias import javascript
import {default as alias} from 'my-module';
Example 2: js es6 dynamic import default
export const hi = (name) => console.log(`Hi, ${name}!`)
export const bye = (name) => console.log(`Bye, ${name}!`)
export default () => console.log('Hello World!')
We can use import() syntax to easily and cleanly load it conditionally:
if (somethingIsTrue) {
import('./something.js').then((module) => {
module.hi('Erick')
module.bye('Erick')
module.default()
})
}
Example 3: import javascript
import { add } from './math_functions.js';
import { add, someothervariable } from './math_functions.js';