Welcome to the forums! Whether or not this is hw, I encourage you to take a little more time to bug test. Problem solving in general is a really valuable skill.
Specifically, seeing that you have two functions, merge(), and mergesort(), try testing each function individually. Another good idea is to start with really small test-cases that you can trace by hand.
My familiarity with java script is pretty low. I have been trying to rectify my code for quite sometime now with little success. Initially I got a stack limit exceeded error and now this.
I will try to test the two functions separately like you suggested.
Thank you tony.