Course Credits
- FreeCodeCamp
- Dylan Israel
- Course Link: View.
TOC
- Template Literals
- Destructuring
- Object Literal
- For of loop
- Spread operator
- Rest operator
- Arrow Functions
- Default Params
- Array.includes
- Let & const
- Export & import
- String.padStart(), String.padEnd()
- Classes
- Trailing commas
- Async/Await
- Sets
Template Literals
const fruit = "π";
const milk = "π₯";
const bananaShake = (fruit, milk) => `(${fruit}) Banana (${milk}) Milk shake is ready.`;
console.log(`${bananaShake(fruit, milk)}`);
Destructuring
Objects
const purchasedItems = {
fruit: "π",
vegetable: "π₯",
bakery: "πͺ"
};
const { bakery } = purchasedItems;
console.log(`Hungry? How about try a ${bakery}?`);
Arrays
const cart = ["π", "π₯", "πͺ", "π₯©"];
const [item] = cart;
console.log(`Cashier scanned ${item} first.`);
Object Literal
const boilEgg = (egg, water, salt) => {
const recipe = {
egg,
water,
salt
};
console.log(`Get a saucepan, Add 3 cups ${recipe.water} and a pinch of ${recipe.salt}. Throw ${recipe.egg} and boil for 10 minutes.`);
}
boilEgg("π₯", "π°", "π§");
For of loop
let bill = 0;
const receipt = [1.99, 13.67, 14.21, 5.27];
for(const item of receipt) {
bill += item
};
console.log(`Your total bill is $${bill}.`);
Spread operator
const purchasedItems = {
fruit: "π",
vegetable: "π₯",
bakery: "πͺ"
};
const juiceRecipe = {
...purchasedItems,
kitchen: "sugar",
device: "blender"
};
console.log(`Trying a ${juiceRecipe.vegetable} juice.`);
Rest operator
const cart = [];
const addItem = (...items) => console.log(`${items} added in the card. Total items in the cart: ${items.length}.`);
addItem("π","π₯","π","π");
Arrow Functions
const shoppingBag = [
{id: 1, name: "π₯", type: "fruit"},
{id: 2, name: "π", type: "fruit"},
{id: 3, name: "π", type: "fruit"},
{id: 4, name: "π₯", type: "vegetable"}
];
const findVegetable = shoppingBag.filter(item => item.type === "vegetable");
findVegetable ? console.log(`${findVegetable.length} vegetable found in the bag.`) : console.log("Forgot to buy vegetables.");
Default Params
const readyToCheckout = (limit = 10) => limit <= 10 ? console.log(`Today, shopping was in budget.`) : console.log(`Today, lot of items were bought.`)
readyToCheckout(23);
Array.includes
const receipt = ["π","π₯","π","π"];
receipt.includes("π") ? console.log(`You bought bananas?`) : console.log(`How come there are no bananas?`);
Let & const
let apple;
apple = "π";
console.log(`Green Apple: ${apple}`);
apple = "π";
console.log(`Red Apple: ${apple}`);
const banana = "π";
console.log(`Banana: ${banana}`);
banana = "π―"; // WRONG
Export & import
- Example: View source.
String.padStart(), String.padEnd()
let apple = "π";
let banana = "π";
const dozenApples = apple.padStart(12, apple);
const dozenBananas = banana.padEnd(12, banana);
console.log(`Buy dozen apples: ${dozenApples}. Total apples: ${dozenApples.length}`);
console.log(`Buy dozen bananas: ${dozenBananas}. Total bananas: ${dozenApples.length}`);
Classes
- Example: View source.
Trailing commas
Trailing commas after function arguments, object declaration works, is not recommended.
Async/Await
- Example: View source.
Sets
let cart = new Set(["π", "π₯", "πͺ", "πͺ", "πͺ", "πͺ", "π₯©"]);
console.log(`Total unique items in the cart: ${cart.size}`);
Top comments (0)