A function can be made available to other files by exporting them using the export keyword. There are two ways of exporting a function:
In named export, you write the export
keyword before the function declaration.
export function multiple(x, y){ return x*y; }
Here is how you would import the function.
import {multiply} from './utils.js'; console.log(multiply(4, 5)); //20
In default export, you export a function like this:
export default function multiple(x, y){ return x*y; }
By removing the curly braces, you can import a default exported value.
import multiply from './utils.js'; console.log(multiply(4, 5)); //20