// export
export default function contact(name, age) {
console.log(`The name is ${name}. And age is ${age}.`);
}
//There two types of imports
export default class || function || variable
//When you use export default, export one thing only and import something like this:
import thing from "path"
//-------------------------------------
export { class || function || variable }
//With this we can especify what we want import
import { thing1, ...} from "path"
//// Exporting a single function
module.exports = (…) => {…}
//// Exporting multiple functions
exports.function1 = () => {}
exports.function2 = () => {}
…
// Importing
const myModule = require('./modulesFolder/myModule');
myFunctions.function1(…)
…
// Importing with destructuring
const {function1, function2} = require('./modules/myModule');
function1(…)
…
// Exporting functions lightens the main file
// but results in slightly longer compiling times
// export a function in javascript
export function myFunc(var1, var2, ..., varn) {
// do something
}
export const name = 'square';
export function draw(ctx, length, x, y, color) {
ctx.fillStyle = color;
ctx.fillRect(x, y, length, length);
return {
length: length,
x: x,
y: y,
color: color
};
}