I ran into this case while working with find function for Arrays in Javascript.
I would like to understand how Javascript engine handled the arrow function expression when I had wrongly put curly braces "{ }" inside it.
//Array Declaration
const phones = [{ brand: "Samsung", id: 10 }, { brand: "Apple", id: 20 }];
//correct way
let phone = phones.find(phone => phone.id === 10);
console.log("Correct result: ", phone);
//wrong way
phone = phones.find(phone => {
phone.id === 10;
});
console.log("Wrong result: ", phone);
Correct result: {brand: "Samsung", id: 10} Wrong result: undefined