InterviewSolution
Saved Bookmarks
| 1. |
What is Export Default and Named Export in ES6? |
|
Answer» With the help of the import STATEMENT, the export statement comes into picture when one needs to export functions, objects, and variables to other JavaScript modules. There are two methods for exporting:
Example: //file rectangle.jsfunction perimeter(x, y) { return 2 * (x + y);}function area(x, y) { return x * y;}export { perimeter, area }; //while importing the functions in test.jsimport { perimeter, area } from './rectangle;console.log(perimeter(4, 6)) //20console.log(area(4, 6)) //24Output: 2024
Example: // file module.jsvar a = 6; export default a; // test.js// while importing a in test.jsimport b from './module'; console.log(b); // output will be 6Output: 6
Output: This is a default export.3 |
|