There are two types of exports in javascript.
1) default export
2) named export
Default Export
Let's create a file named myAddress.js
myAddress.js
const myAddress = {
name:"Sujith",
country:"India",
phone:45342....,
}
export default myAddress
Now in home.js, let's import the object in myAddress.js
home.js
import myAddress from './myAddress.js'
import addrs from './myAddress.js'
export default myAddress
always defaultly exports the myAddress object. So even if we import addrs from myAddress.js, we only get myAddress object because it is defaultly exported.
Named Export
Let's create a file named myAddress.js
country.js
export const myCountry = () => {console.log(India)}
export const myState = "Kerala"
Now in home.js, let's import the object in myAddress.js
home.js
import {myCountry as country, mySate} from './country.js'
In country.js we are exporting each function, objects, variables individually. So we can import each one of them individually.
Top comments (0)