var a = [2, 1]; var b = [9, 5]; function mergeArray(a, b) { var array = a.concat(b); document.write(array); } mergeArray(); 

    1 answer 1

    When you call a function, you do not pass parameters to it, so inside the mergeArray function mergeArray variables a and b are undefined

    To make it all work, you need to call it like this

     mergeArray(a, b); 

     var a = [2, 1]; var b = [9, 5]; function mergeArray(a, b) { var array = a.concat(b); document.write(array); } mergeArray(a, b); 

    • and how to do so in order not to overwrite the scope of global and local variables? - Eugene
    • global variables are bad style and source of problems. If you received an answer to your question, then mark it as accepted - it will help others. - Mikhail Vaysman
    • How would you write here? - Eugene
    • as I wrote it in response - Mikhail Vaysman
    • I mean, how to betray a and b parameters to a function, but not to make the global and local variables identical? - Eugene