how does function and for of works in javascript 3f

Solutions on MaxInterview for how does function and for of works in javascript 3f by the best coders in the world

showing results for - "how does function and for of works in javascript 3f"
Anthony
10 Mar 2018
1const products = [
2    { name: 'Laptop', price: 32000, brand: 'Lenovo', color: 'Silver' },
3    { name: 'Phone', price: 700, brand: 'Iphone', color: 'Golden' },
4    { name: 'Watch', price: 3000, brand: 'Casio', color: 'Yellow' },
5    { name: 'Aunglass', price: 300, brand: 'Ribon', color: 'Blue' },
6    { name: 'Camera', price: 9000, brand: 'Lenovo', color: 'Gray' },
7];
8function myFun() {
9    let getTotal = 0;
10    for (let product of products) { //for of loop
11        getTotal += product.price; //getTotal = getTotal + product.price;
12    }
13    return getTotal;
14}
15const result = myFun();
16console.log(result);
17//Expected output:45000
similar questions