How does this function work?

this function accepts two arguments, an array, and a number telling to sum the first n-th numbers of the array
so, summing the first 7 numbers of that array, we have 5+10+15+18+5+1+9 which makes 63

recursion means calling the function inside itself with different arguments
so, inside sum([5,10,15,18,5,1,9], 7); we use sum([5,10,15,18,5,1,9], 6) and sum to it the 7th number - so what happens is that the 54 comes from the function call inside, and to return the result 9 is added to it, and then returned

where does the 54 comes from?
inside sum([5,10,15,18,5,1,9], 6) there is sum([5,10,15,18,5,1,9], 5) + 1

and so on

you can try seeing the execution with this tool:
http://pythontutor.com/javascript.html#mode=edit

you could also take a look at this throurough explanation of recursion: