Skip to content

dynamic import  #3

@preveen-stack

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);
  });

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