Skip to content

Commit 7a9d2a1

Browse files
committed
intermediate commit
1 parent 16f780b commit 7a9d2a1

File tree

4 files changed

+93
-20
lines changed

4 files changed

+93
-20
lines changed

npm/node_modules/leaflet/package.json

Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

npm/node_modules/lodash-es/package.json

Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

npm/script.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,45 @@
11

22
"use strict"
3+
//This is Importing Module
4+
//All modules are by-default executed in 'strict mode'
5+
//Import statement are executed asyncronously
6+
//Import statement are read syncronously
7+
//Import statemets are always hoisted to the top of the code/file
8+
//Import statements are written at the start of the code in practice
9+
10+
//Part 1, multiple named exports
11+
import "./shoppingCart.js";
12+
import {addToCart, shippingCost as shipping, amountDue as dueToday} from "./shoppingCart.js";
13+
console.log('Importing Module');
14+
15+
// //Cannot use varibles and function names from exporting modules
16+
// //console.log(totalCost);
17+
18+
// //Using an imported module
19+
addToCart("book", 5);
20+
21+
console.log(shipping, dueToday);
22+
23+
//Part 2, export all top level/global scoped varibles and functions
24+
25+
import * as ShoppingCart from "./shoppingCart.js";
26+
27+
ShoppingCart.addToCart('Pencil', 5);
28+
console.log(ShoppingCart.amountDue);
29+
30+
//Part 3, export default values
31+
32+
import add2Cart from "./shoppingCart.js";
33+
add2Cart('shapener', 3);
34+
35+
//Part 4 Mixing default and named export is possible but not recommended
36+
37+
import add, {shippingCost, cart, amountDue} from "./shoppingCart.js";
38+
39+
add('pen', 10);
40+
console.log(shippingCost);
41+
console.log(amountDue);
42+
cart.forEach(pd => console.log(pd.item));
343

444
import cloneDeep from "./node_modules/lodash-es/cloneDeep.js";
545

npm/shoppingCart.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use strict"
2+
//This is Exporting Module
3+
console.log('Exporting Module');
4+
5+
const product = 50;
6+
const cart = [];
7+
const quantity = 5;
8+
9+
10+
// putting export in front of any variable or function name will make it
11+
//accessible in importing modules.
12+
// Export can only happen in the global/top level scope of the existing file
13+
14+
const addToCart = function(product, quantity){
15+
cart.push({item: product, pieces: quantity});
16+
console.log(`You have added a product`);
17+
console.log(cart);
18+
}
19+
20+
const shippingCost = 10;
21+
const totalCost = (product * quantity) + shippingCost;
22+
23+
export {addToCart, shippingCost, totalCost as amountDue, cart};
24+
25+
export default function(product, quantity){
26+
cart.push({item: product, pieces: quantity});
27+
console.log(`You have added a product`);
28+
console.log(cart);
29+
}

0 commit comments

Comments
 (0)