Import Export

// addition.js
function addTwo(a,b){
    return a + b;
}
export { addTwo };

// app.js
import { addTwo } from './addition';
console.log(addTwo(2, 4)); // 6

import/export multiple

// addition.js
function addTwo(a,b){
    return a + b;
}

function addThree(a,b,c){
    return a + b + c;
}

export { addTwo, addThree };

// app.js
import { addTwo, addThree } from './addition';

console.log(addTwo(2, 4)); // 6
console.log(addThree(2, 4, 5)); // 11

export other variation

Rename exported function - addTwo as addTwoNumber

import all in one shot

Use case ( with lodash )

Last updated

Was this helpful?