w3resource

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.

Click me to see the solution

Named Exports:

2. Write a JavaScript module that exports multiple named functions for basic arithmetic operations.

Click me to see the solution

Import all as Alias:

3. Write a JavaScript programme that imports all exports from a module as a single object and use its properties.

Click me to see the solution

Combining Default and Named Exports:

4. Write a JavaScript module with both default and named exports. Use both in another file.

Click me to see the solution

Re-exporting:

5. Write a JavaScript module that re-exports functions from another module.

Click me to see the solution

Import with Alias:

6. Write a JavaScript programme that imports named exports from a module using alias names and use them in another file.

Click me to see the solution

Dynamic Imports:

7. Write a JavaScript programme that uses dynamic imports to load a module and invoke its function asynchronously.

Click me to see the solution

Conditional Imports:

8. Write a JavaScript program that imports a specific module conditionally based on a runtime value.

Click me to see the solution

Exporting Constants:

9. Write a JavaScript program to create a module that exports multiple constants. Use them in another file.

Click me to see the solution

Aggregating Exports:

10. Write a JavaScript program to aggregate exports from two different modules into one module and use them.

Click me to see the solution

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Follow us on Facebook and Twitter for latest update.