Explorando conceptos fundamentales de React, JavaScript, Performance y Arquitectura Frontend
The Module pattern helps us to split our code in multiple files and and avoid files with huge lines of code.
.mjs or add "type": "module" to your package.json file.export before any variable or function we want to use in other part of our app and use the keyword import to import the function previously exported. Also adds the capacity to have private functions and variables when we omit the export keyword in our module.// index.js
import { sum, subtract, divide, multiply } from './math.js';
console.log('Sum', sum(1, 2));
console.log('Subtract', subtract(1, 2));
console.log('Divide', divide(1, 2));
console.log('Multiply', multiply(1, 2));
// math.js
export function sum(x, y) {
return x + y;
}
export function multiply(x, y) {
return x * y;
}
export function subtract(x, y) {
return x - y;
}
export function divide(x, y) {
return x / y;
}
{
"name": "node-starter",
"version": "0.0.0",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}
A final recap and how it connects to your overall learning journey on FrontendMasters.