Skip to content

Commit 53ee58f

Browse files
authored
Add files via upload
1 parent 4703b18 commit 53ee58f

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
/*
3+
author : Jaydatt Patel
4+
5+
ES6 Module :
6+
7+
File Name must be with .mjs extension :
8+
moduleFile.mjs
9+
MainFile.mjs
10+
*/
11+
12+
// Named inline Export Syntax:
13+
export const add = (a,b) => {
14+
console.log('Add : ',(a+b));
15+
}
16+
const sub = (a,b) => {
17+
console.log('Sub : ',(a-b));
18+
}
19+
const mul = (a,b) => {
20+
console.log('Mul : ',(a*b));
21+
}
22+
const div = (a,b) => {
23+
console.log('Div : ',(a/b));
24+
}
25+
26+
const info = (str = '')=>{
27+
console.log('Calculator....!', str);
28+
}
29+
30+
//multiple named export
31+
export {sub,mul};
32+
33+
//default single export
34+
export default info;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
author : Jaydatt Patel
3+
4+
ES6 Module :
5+
Modules are a fundamental concept in modern JavaScript development, allowing developers to organize code into separate files or modules. Each module encapsulates its variables, functions, and classes, avoiding naming conflicts and polluting the global scope. This modularity promotes code reusability, maintainability, and scalability in large-scale projects.
6+
7+
With '.js' file extension :
8+
You can use module with '.js' file extension by changing type to "module" in package.json file in working directory. So you do not need to change '.js' extension to '.mjs'.
9+
10+
With '.mjs' file extension :
11+
You can use module '.js' file by rename to '.mjs' file extension :
12+
moduleFile.mjs
13+
MainFile.mjs
14+
15+
*/
16+
17+
//single import
18+
// import {add} from './Arithmetic.mjs';
19+
20+
//multiple import
21+
// import {add,sub} from './Arithmetic.mjs';
22+
23+
//multiple import with alise name
24+
// import {add as addition, sub as subtraction} from './Arithmetic.mjs';
25+
26+
//import default only without {}
27+
// import info from './Arithmetic.mjs';
28+
29+
//import default only with alise name and without {}
30+
// import infomation from './Arithmetic.mjs';
31+
32+
//default and multiple import
33+
// import info, {add,sub} from './Arithmetic.mjs';
34+
35+
//default and multiple import with alise name
36+
// import infomation, {add as additon, sub as subtraction} from './Arithmetic.mjs';
37+
38+
//all import
39+
40+
// require('path') to import
41+
import * as operation from './Arithmetic.js';
42+
43+
operation.add(2,3);
44+
operation.sub(10,7);
45+
operation.mul(4,3);
46+
// operation.div(20,2); //error: not fun. need to export to use
47+
operation.default();
48+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}

0 commit comments

Comments
 (0)