Merge two sorted arrays that can be of different sizes
I think considering approach that you chose, your code is alright. A few points:


What I don't like is that you get error when passing 2 empty arrays? Why would you do that? Imagine I am generating arrays of different sizes and using your code to merge and sometimes I would pass 2 empty arrays. Should I really need to handle that as special case in my code? No, just return empty array too.
I'd eliminate targetSize variable and check for j &lt; arr2.length &amp;&amp; i &lt; arr1.length instead.
Checking valueToPush for undefined feels a bit off for me. It works, but doesn't really feel right. In many languages you would get something like IndexOutOfRange error or something. Maybe it's idiomatic in Javascript (probably not), but I think nicer and cleaner would be to check if you are still in range of array, ex j &lt; arr2.length.