import es6 code example

Example 1: alias import javascript

import {default as alias} from 'my-module';

Example 2: 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 3: javascript import

import { module } from "./path"; // single module
import Module from "./path"; // default export

import Module, { module } from "./path"; // both

Example 4: import all from javascript

import * as module from "./module.js";

Example 5: import javascript

/*Imagine a file called math_functions.js that contains several functions
related to mathematical operations. One of them is stored in a variable called
add.*/

//If you want to import one item:
import { add } from './math_functions.js';

//If you want to import multiple items:
import { add, someothervariable } from './math_functions.js';

Example 6: 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';