Modules
export function add(a, b) { // Exporting functions
return a + b;
}import { add } from './math.js'; // We define the path of the external file
const add = require('./math.js'); // Or using Node.js syntax
console.log(add(2, 3)); // Exports are saved with the same namefunction add(a, b) {
return a + b;
}
function mult(a, b) {
return a * b;
}
let pi = 3.14; // Exporting a variable
export { add, mult, pi }; // Exporting multiple itemsLast updated