Create a module file that exports a function called multiply which takes two numbers and returns their product. Then show how to import and use it in another file.
Modules help organize code by splitting it into separate files, each with its own scope.
Use export
to make variables, functions, or classes available to other modules.
// math.js
export function add(a, b) {
return a + b;
}
Use import
to include exported features from another module.
// main.js
import { add } from './math.js';
console.log(add(2, 3)); // 5
Modules allow you to keep code clean, reusable, and maintainable.
Currently there is an issue when creating an export in our app, sorry for this inconvenience!