Custom Iterator: ================ // Grocery Store Product Category class GrocessoryStore{ // constructor creation constructor(){ this.categories = { fruits:["Apple","Banana","Ornage","Grapes"], vegetables:["Carrot","Broccolli","Spinach"], dairy:["Milk","Cheese","Yogurt"] }; } // defining custome iterator [Symbol.iterator](){ const categoryKeys = Object.keys(this.categories); let categoryIndex = 0; let itemIndex = 0; return{ next:() =>{ // check if there are more items in the current category if(itemIndex < this.categories[categoryKeys[categoryIndex]].length){ return{ value:this.categories[categoryKeys[categoryIndex]][itemIndex++], done:false }; } else{ return{ done:true } } }, }; } } const store = new GrocessoryStore(); for(const p of store){ console.log(p); } =================================================================== Functions: ========== functions can always write/define in outside of the class only. but methods can define inside the class. // Calculation of Total price with Tax function calculateTotalPrice(price,taxRate){ return price + (price * taxRate); } const itemPrice = 9999 const taxRate = 0.16; let totalPrice = calculateTotalPrice(itemPrice,taxRate); console.log("Total Price of the product = ",totalPrice); ============================================================== // Greet the user based on the time let greetUser = function(name){ const hour = new Date().getHours(); let greetings; if(hour < 12){ greetings = "Good Morning"; } else if(hour < 18){ greetings = "Good Afternoon"; } else{ greetings = "Good Evening"; } return `${greetings},${name}`; } console.log(greetUser("Ashish")); ======================================================== // Filter Items in a shopping list function findItems(shoppingList,query){ return shoppingList.filter(item => item.toLowerCase().includes(query.toLowerCase())); } let shoppingList = ["Apples","Bananas","Oranges","Grapes"]; console.log(findItems(shoppingList,"AP"));