This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Sujith V S
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.
This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Sujith V S

Sujith V S | Sciencx (2022-09-06T18:11:54+00:00) Import and Export in JavaScript.. Retrieved from https://www.scien.cx/2022/09/06/import-and-export-in-javascript/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.