Hi, I’m new to JavaScript and trying to understand the array methods. I came a cross this code on freeCodeCamp and unable to understand how the brackets work here, especially the empty ones at the end of the code:
the reduce method accepts a second argument, which becomes the starting value of the accumulator (otherwise the starting value is the first item in the array)
for why one way it works and the other doesn’t… what do you mean with that? what happens?
Well it works but if I remove the last brackets (because I don’t need the last argument), It doesn’t work anymore… I don’t get the purpose of the last empty brackets…
you still need it, it is the startinng value of obj, if you don’t put a starting value then the starting value is dog, a string, and you get an error because you can’t change a string in the way your code says