19
loading...
This website collects cookies to deliver better user experience
// multiply.js
function multiply(a, b) {
return a * b;
};
module.exports = multiply;
// index.js
var multiply = require('./multiply.js'); // Relative path to the file
var result = multiply(10, 10); // 100
// multiply.js
export function multiply(a, b) {
return a * b;
};
// index.js
import { multiply } from './multiply.js' // Relative path to the file
const result = multiply(10, 10); // ES6 is here, we can now use const keyword 😉
export function multiply(a, b) {
return a * b;
};
function multiply() { ... };
export { multiply };
export function a() {...};
export function b() {...};
export function c() {...};
export function d() {...};
function a() {...};
function b() {...};
function c() {...};
function d() {...};
export { a, b, c, d };
import { a, b, c, d } from './multiply.js';
import { foo } from './multiply.js'; //<--- Will fail because there's nothing named 'foo' exported from the file
const foo = {
bar: true
};
// After 10 ms, we change the value of bar
setTimeout(() => {
foo.bar = false;
}, 10);
export { foo };
import { foo } from './foo.js'
console.log(foo); // <--- { bar: false }
function multiply () {...};
export { multiply as default };
import multiply from './multiply.js'; // <-- You're now free to remove the brackets
function multiply () {...};
export default multiply ;
export default function multiply () {...};
You are free to name your imports variable however you want, it's no longer binded to the exported names
import foo from './multiply.js'; // <-- You're still getting the multiply function, but it's renamed
You can only do ONE default export per module
export { multiply as default };
export multiply as default;
//multiply.js
function multiply () {...};
function a() {...}
export { a };
export default multiply;
//index.js
import multiply, { a } from './multiply.js'; // <-- Work like a charm
// multiply.js
export { multiply as foo };
// index.js
import { foo } from './multiply.js'; // <-- Will give you the multiply function
foo();
// multiply.js
export { multiply };
// index.js
import { multiply as foo } from './multiply.js';
foo();
function a() {...};
function b() {...};
function c() {...};
function d() {...};
export { a, b, c, d };
import { a, b, c, d } from './foo.js';
import * as whateverYouLike from './foo.js';
whateverYouLike.a();
whateverYouLike.b();
...