Import Export
// addition.js
function addTwo(a,b){
return a + b;
}
export { addTwo };
// app.js
import { addTwo } from './addition';
console.log(addTwo(2, 4)); // 6import/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)); // 11export other variation
Rename exported function - addTwo as addTwoNumber
import all in one shot
Use case ( with lodash )
Last updated
Was this helpful?