import function js code example

Example 1: js es6 dynamic import default

// something.js

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:
// other-file.js

if (somethingIsTrue) {
  import('./something.js').then((module) => {
    // Use the module the way you want, as:
    module.hi('Erick') // Named export
    module.bye('Erick') // Named export
    module.default() // Default export
  })
}

Example 2: different types ways of export and import in javascript

// Import a module without any import bindings, just to
// execute its code without assigning any variables here.
import 'example';
 
// Import the default export of a module.     
import exampleDefaultExport from 'example';    
             
// Import a named export of a module.
import { property } from 'example';
 
// Import a named export to a different name,
import { property as exampleProperty } from 'example';
 
// Import all exports from a module as properties of an object.
import * as example from 'example';
 
// Export a named variable.
export var property = 'example property';
 
// Export a named function.
export function property() {};
 
// Export an entity to the default export.
export default 'example default';
 
// Export an existing variable.
var property = 'example property';
export { property };
 
// Export an existing variable as a new name.                   
export { property as exampleProperty };
 
// Export an export from another module.
export { property as exampleProperty } from 'example';
 
// Export all exports from another module.
export * from 'example';