Skip to content

dynamic import  #3

Description

@preveen-stack
// dynamicImportExample.js

// Using dynamic import to load the math module
console.log("dynamically importing ./math.mjs");
import('./math.mjs')
  .then((mathModule) => {
    // Now you can use the functions from the loaded module
    const result1 = mathModule.add(5, 3);
    const result2 = mathModule.subtract(10, 4);

    console.log('Addition result: 5, 3 -> ', result1);
    console.log('Subtraction result: 10, 4 -> ', result2);
  })
  .catch((error) => {
    console.error('Dynamic import error:', error);
  });

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions