Simplemente siguiendo el tutorial de mdn sobre reducir en javascript, ¿alguien puede explicarme por qué a continuación no puedo usar las llaves alrededor de la devolución de llamada?
const array1 = [1, 2, 3, 4]; // 0 + 1 + 2 + 3 + 4 const initialValue = 0; // expected output: 10 const sumWithInitialTest = array1.reduce( (pv, cv) => { pv + cv } ) console.log(sumWithInitialTest)Obviamente, sin llave, funciona bien
const array1 = [1, 2, 3, 4]; // 0 + 1 + 2 + 3 + 4 const initialValue = 0; // expected output: 10 const sumWithInitialTest = array1.reduce( (pv, cv) => pv + cv ) console.log(sumWithInitialTest)Agregue retorno si desea usar corchetes
const array1 = [1, 2, 3, 4]; // 0 + 1 + 2 + 3 + 4 const initialValue = 0; // expected output: 10 const sumWithInitialTest = array1.reduce( (pv, cv) => { return pv + cv } ) console.log(sumWithInitialTest)