export and import in js code example
Example 1: javascript import class
import Example from './file2';
var myInstance = new Example()
myInstance.test()
Example 2: js import and export
export function helloWorld() {
return 'Hello World!';
}
import helloWorld from './helloworld.js';
console.log(helloWorld());
Example 3: import and export type in js
export let name1, name2, …, nameN;
export let name1 = …, name2 = …, …, nameN;
export function functionName(){...}
export class ClassName {...}
export { name1, name2, …, nameN };
export { variable1 as name1, variable2 as name2, …, nameN };
export const { name1, name2: bar } = o;
export default expression;
export default function (…) { … }
export default function name1(…) { … }
export { name1 as default, … };
export * from …;
export * as name1 from …;
export { name1, name2, …, nameN } from …;
export { import1 as name1, import2 as name2, …, nameN } from …;
export { default } from …;
Example 4: export function javascript
export default function cube(x) {
return x * x * x;
}
Example 5: different types ways of export and import in javascript
import 'example';
import exampleDefaultExport from 'example';
import { property } from 'example';
import { property as exampleProperty } from 'example';
import * as example from 'example';
export var property = 'example property';
export function property() {};
export default 'example default';
var property = 'example property';
export { property };
export { property as exampleProperty };
export { property as exampleProperty } from 'example';
export * from 'example';