Saturday, October 15, 2022
HomeWordPress DevelopmentDefault vs Named exports - DEV Group 👩‍💻👨‍💻

Default vs Named exports – DEV Group 👩‍💻👨‍💻


There are two major methods to export values with JavaScript: default exports and named exports. However you need to use one or each of them in the identical file. A file can haven’t multiple default export, however it could possibly have as many named exports as you want

Export Statements:
export default perform Button() {} // default export
export perform Button() {} // named export

Import Statements:
import Button from './button.js'; // default export
import { Button } from './button.js'; // Named export

While you write a default import, you may put any identify you need after import.
For instance, you would write
import Banana from './button.js'
and it will nonetheless give you the identical default export.
In distinction, with named imports, the identify has to match on either side. That’s why they’re known as named imports!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments