I have the following two codes one could run from any browser.
Code1:
let prices = [1, 2, 3, 4, 5];
let result = prices.reduce( (x,y)=>{x+y} ); // Reduce data from x to y.
console.log(result);
Code2:
let prices = [1, 2, 3, 4, 5];
let result = prices.reduce( (x,y)=>x+y ); // Reduce data from x to y.
console.log(result);
The first code doesn't work but the second does.
Why would the braces ({}
) make it not to work? Aren't they part of an implicit function? Or this braceless syntax is just something unique to the reduce()
method?