Why is the summary function returning undefined? [closed]

-1

When the console.log(contas.sumario()) function of the CicloFinanceiro class is called, the two objects appear as expected and then undefined appears and I do not understand why.

class Lancamento { constructor(nome = 'Genérico', valor = 0){ this.nome = nome this.valor = valor } }

    
asked by anonymous 26.11.2018 / 05:42

1 answer

2

Returns undefined because you are asking the sumario() method to return the return of the forEach array method, and this method by default performs a callback function for each element of the array and always returns the value of% with%.

You can see this through this mozilla developer link: link where it says the following: ' undefined executes the callback function once for each element of the array - unlike forEach() or map() , it always returns the reduce() value and is not chained. The typical use case is to change the array at the end of the loop. ''.

If you do not want to see undefined , rewrite: undefined so console.log(conta.sumario())

    
26.11.2018 / 08:19