# Import Export

* named export/import
* default export/import

```javascript
// 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

```javascript
// 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

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

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

## Rename exported function - addTwo as addTwoNumber

```javascript
// 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 as addTwoNumber, addThree } from './addition';
console.log(addTwoNumber(6, 4)); // 10
console.log(addThree(2, 4, 5)); // 11
```

## import all in one shot

```javascript
// app.js
import * as adder from './addition';
console.log(adder.addTwoNumber(6, 4)); // 10
console.log(adder.addThree(2, 4, 5)); // 11
```

## Use case ( with lodash )

```javascript
// users.js
export var users = [
    {name: "hemant", age: 20, location: "hyderabad"},
    {name: "vinay", age: 80, location: "hyderabad"},
    {name: "paa", age: 90, location: "hyderabad"},
    {name: "varun", age: 44, location: "hyderabad"}
];

// app.js
import * as _ from "lodash"; // npm i lodash -S
import {users } from './users';

console.log(_.where(users, {age: 20}));
```

## Default export/import

```javascript
// greet.js
export default function greet(){

}


// app.js
import greet from './greet';
// OR
import myGreet from './greet'; // any name can be used for default export
greet();
```
