Practice JavaScript Modules and Imports/Exports with Solutions
JavaScript Modules and Imports/Exports [10 exercises with solutions]
Default Export:
1. Write a JavaScript module that exports a default function to greet a user and use it in another file.
Named Exports:
2. Write a JavaScript module that exports multiple named functions for basic arithmetic operations.
Import all as Alias:
3. Write a JavaScript programme that imports all exports from a module as a single object and use its properties.
Combining Default and Named Exports:
4. Write a JavaScript module with both default and named exports. Use both in another file.
Re-exporting:
5. Write a JavaScript module that re-exports functions from another module.
Import with Alias:
6. Write a JavaScript programme that imports named exports from a module using alias names and use them in another file.
Dynamic Imports:
7. Write a JavaScript programme that uses dynamic imports to load a module and invoke its function asynchronously.
Conditional Imports:
8. Write a JavaScript program that imports a specific module conditionally based on a runtime value.
Exporting Constants:
9. Write a JavaScript program to create a module that exports multiple constants. Use them in another file.
Aggregating Exports:
10. Write a JavaScript program to aggregate exports from two different modules into one module and use them.
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics