How does join() produce different results depending on the arguments?How does JavaScript .prototype work?How to get the difference between two arrays in Javascript?How does the “this” keyword work?How do I pass command line arguments to a Node.js program?How does data binding work in AngularJS?How does Access-Control-Allow-Origin header work?How do I update each dependency in package.json to the latest version?How does Trello access the user's clipboard?How does Facebook disable the browser's integrated Developer Tools?Why do we need middleware for async flow in Redux?

Set vertical spacing between two particular items

Why isn’t the tax system continuous rather than bracketed?

how to remove the dotted white border around focused button text?

Bash echo $-1 prints hb1. Why?

The difference between Rad1 and Rfd1

Avoid bfseries from bolding pm in siunitx

Dual statement category theory

AT system without -5v

Professor Roman gives unusual math quiz ahead of

Averting Real Women Don’t Wear Dresses

Is this the golf ball that Alan Shepard hit on the Moon?

The use of "I" and "we" used in the same sentence and other questions

Wilcoxon signed rank test – critical value for n>50

Intuitively, why does putting capacitors in series decrease the equivalent capacitance?

How can I convince my reader that I will not use a certain trope?

What does 2>&1 | tee mean?

How to modify the uneven space between separate loop cuts, while they are already cut?

What do you call the action of someone tackling a stronger person?

Disabling automatic add after resolving git conflict

Did Chinese school textbook maps (c. 1951) "depict China as stretching even into the central Asian republics"?

SPI Waveform on Raspberry Pi Not clean and I'm wondering why

Does ultrasonic bath cleaning damage laboratory volumetric glassware calibration?

“Transitive verb” + interrupter+ “object”?

Should I report a leak of confidential HR information?



How does join() produce different results depending on the arguments?


How does JavaScript .prototype work?How to get the difference between two arrays in Javascript?How does the “this” keyword work?How do I pass command line arguments to a Node.js program?How does data binding work in AngularJS?How does Access-Control-Allow-Origin header work?How do I update each dependency in package.json to the latest version?How does Trello access the user's clipboard?How does Facebook disable the browser's integrated Developer Tools?Why do we need middleware for async flow in Redux?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








11















I can't quite understand why the join() call below produces different results, depending on the type of argument(s) provided.



Here's what I found:






var test = function() 
var args = Array.prototype.join.call(arguments,"_");
return args
;

console.log(test([1,2,3])) // #1: returns 1,2,3
console.log(test(1,2,3)) // #2: returns 1_2_3





Given join(arguments, '_'), shouldn't it produce a _ delimited string in both tests above? Why does #1 return a comma delimited value instead?










share|improve this question



















  • 5





    if you tried to console.log(arguments) in your test function, it'd be clear for you how it's working

    – Ammar
    Jun 17 at 8:00











  • You can also try test([1,2,3], [4,5,6])

    – Bergi
    Jun 17 at 18:41

















11















I can't quite understand why the join() call below produces different results, depending on the type of argument(s) provided.



Here's what I found:






var test = function() 
var args = Array.prototype.join.call(arguments,"_");
return args
;

console.log(test([1,2,3])) // #1: returns 1,2,3
console.log(test(1,2,3)) // #2: returns 1_2_3





Given join(arguments, '_'), shouldn't it produce a _ delimited string in both tests above? Why does #1 return a comma delimited value instead?










share|improve this question



















  • 5





    if you tried to console.log(arguments) in your test function, it'd be clear for you how it's working

    – Ammar
    Jun 17 at 8:00











  • You can also try test([1,2,3], [4,5,6])

    – Bergi
    Jun 17 at 18:41













11












11








11


1






I can't quite understand why the join() call below produces different results, depending on the type of argument(s) provided.



Here's what I found:






var test = function() 
var args = Array.prototype.join.call(arguments,"_");
return args
;

console.log(test([1,2,3])) // #1: returns 1,2,3
console.log(test(1,2,3)) // #2: returns 1_2_3





Given join(arguments, '_'), shouldn't it produce a _ delimited string in both tests above? Why does #1 return a comma delimited value instead?










share|improve this question
















I can't quite understand why the join() call below produces different results, depending on the type of argument(s) provided.



Here's what I found:






var test = function() 
var args = Array.prototype.join.call(arguments,"_");
return args
;

console.log(test([1,2,3])) // #1: returns 1,2,3
console.log(test(1,2,3)) // #2: returns 1_2_3





Given join(arguments, '_'), shouldn't it produce a _ delimited string in both tests above? Why does #1 return a comma delimited value instead?






var test = function() 
var args = Array.prototype.join.call(arguments,"_");
return args
;

console.log(test([1,2,3])) // #1: returns 1,2,3
console.log(test(1,2,3)) // #2: returns 1_2_3





var test = function() 
var args = Array.prototype.join.call(arguments,"_");
return args
;

console.log(test([1,2,3])) // #1: returns 1,2,3
console.log(test(1,2,3)) // #2: returns 1_2_3






javascript arrays function






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 17 at 8:06









Kobe

1,6472 silver badges19 bronze badges




1,6472 silver badges19 bronze badges










asked Jun 17 at 7:54









tkim90tkim90

1439 bronze badges




1439 bronze badges







  • 5





    if you tried to console.log(arguments) in your test function, it'd be clear for you how it's working

    – Ammar
    Jun 17 at 8:00











  • You can also try test([1,2,3], [4,5,6])

    – Bergi
    Jun 17 at 18:41












  • 5





    if you tried to console.log(arguments) in your test function, it'd be clear for you how it's working

    – Ammar
    Jun 17 at 8:00











  • You can also try test([1,2,3], [4,5,6])

    – Bergi
    Jun 17 at 18:41







5




5





if you tried to console.log(arguments) in your test function, it'd be clear for you how it's working

– Ammar
Jun 17 at 8:00





if you tried to console.log(arguments) in your test function, it'd be clear for you how it's working

– Ammar
Jun 17 at 8:00













You can also try test([1,2,3], [4,5,6])

– Bergi
Jun 17 at 18:41





You can also try test([1,2,3], [4,5,6])

– Bergi
Jun 17 at 18:41












6 Answers
6






active

oldest

votes


















10














When you pass an array to test, the arguments object becomes an array of arrays, not a plain array of plain values. It's the difference between



arguments = [[1,2,3]];


and



arguments = [1,2,3];


When you call .join on an array of arrays, each inner array gets implicitly coerced to a string first, resulting in '1,2,3' - the values of the inner arrays do not get .joined by the delimiter, only the immediate children of the outer array get .joined by the delimiter.






share|improve this answer























  • I didn't know that if the argument was an array, it's wrapped in another array! That makes sense!

    – tkim90
    Jun 17 at 8:10






  • 1





    @tkim90 The arguments are always wrapped in an array, not just when the argument is an array.

    – Bergi
    Jun 17 at 18:42


















3














In your code, you only have one argument in the first example, that being an array. Joining a single element will remove the brackets:






var test = function() 
var args = Array.prototype.join.call(arguments,"_");
return args
;

console.log(test([1,2,3])) // args = [[1,2,3]]
console.log(test(1,2,3)) // args = [1,2,3]

console.log([[1,2,3]].join('_'))
console.log([1,2,3].join('_'))





Another way to look at this is to provide another array as an argument to test():






var test = function() 
var args = Array.prototype.join.call(arguments,"_");
return args
;

console.log(test([1,2,3], [4,5,6]))








share|improve this answer






























    3














    The first one, first argument is [1,2,3] which is joined with the second argument, which is nothing -> output is [1,2,3].toString().



    Second call, it's actually joining all the 3 arguments, resulting in outputting 1_2_3.






    share|improve this answer






























      3














      Because you're passing one argument which is an array - so it converts it to a string, then attempts to join it to the other arguments (there are none) so it just returns the string.






      var test = function() 
      var args = Array.prototype.join.call(arguments, "_");
      return args
      ;

      console.log(test([1, 2, 3]));
      console.log(test(1, 2, 3));





      You can solve this by checking if there's only one argument passed.






      var test = function() 
      var args = arguments.length == 1 ? arguments[0].join("_") : Array.prototype.join.call(arguments, "_");
      return args;
      ;

      console.log(test([1, 2, 3]));
      console.log(test(1, 2, 3));








      share|improve this answer






























        3














        In the first example you are not calling .join on the array but on arguments. That variable will be populated with an array-like object that has an array as first index, in essence, you are calling the equivalent of:






        let myArguments = [[1, 2, 3]];

        console.log(myArguments.join("_"));





        instead of what you do (the equivalent of) in the second example:






        let myArguments = [1, 2, 3];

        console.log(myArguments.join("_"));








        share|improve this answer






























          3














          The result is different, because arguments is different.



          On the first call (test([1,2,3]), you have one argument which is an array.
          On the second call, you have 3 arguments, each one being a number.



          Array.prototype.join is meant to be called over arrays. It will stringify each of the items in the array.



          In you your first case, your arguments "array" has only one member, which is an array itself. This argument will be stringfied. An array stringfied becomes exactly what is logged in your code.






          share|improve this answer



























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56626979%2fhow-does-join-produce-different-results-depending-on-the-arguments%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            6 Answers
            6






            active

            oldest

            votes








            6 Answers
            6






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            10














            When you pass an array to test, the arguments object becomes an array of arrays, not a plain array of plain values. It's the difference between



            arguments = [[1,2,3]];


            and



            arguments = [1,2,3];


            When you call .join on an array of arrays, each inner array gets implicitly coerced to a string first, resulting in '1,2,3' - the values of the inner arrays do not get .joined by the delimiter, only the immediate children of the outer array get .joined by the delimiter.






            share|improve this answer























            • I didn't know that if the argument was an array, it's wrapped in another array! That makes sense!

              – tkim90
              Jun 17 at 8:10






            • 1





              @tkim90 The arguments are always wrapped in an array, not just when the argument is an array.

              – Bergi
              Jun 17 at 18:42















            10














            When you pass an array to test, the arguments object becomes an array of arrays, not a plain array of plain values. It's the difference between



            arguments = [[1,2,3]];


            and



            arguments = [1,2,3];


            When you call .join on an array of arrays, each inner array gets implicitly coerced to a string first, resulting in '1,2,3' - the values of the inner arrays do not get .joined by the delimiter, only the immediate children of the outer array get .joined by the delimiter.






            share|improve this answer























            • I didn't know that if the argument was an array, it's wrapped in another array! That makes sense!

              – tkim90
              Jun 17 at 8:10






            • 1





              @tkim90 The arguments are always wrapped in an array, not just when the argument is an array.

              – Bergi
              Jun 17 at 18:42













            10












            10








            10







            When you pass an array to test, the arguments object becomes an array of arrays, not a plain array of plain values. It's the difference between



            arguments = [[1,2,3]];


            and



            arguments = [1,2,3];


            When you call .join on an array of arrays, each inner array gets implicitly coerced to a string first, resulting in '1,2,3' - the values of the inner arrays do not get .joined by the delimiter, only the immediate children of the outer array get .joined by the delimiter.






            share|improve this answer













            When you pass an array to test, the arguments object becomes an array of arrays, not a plain array of plain values. It's the difference between



            arguments = [[1,2,3]];


            and



            arguments = [1,2,3];


            When you call .join on an array of arrays, each inner array gets implicitly coerced to a string first, resulting in '1,2,3' - the values of the inner arrays do not get .joined by the delimiter, only the immediate children of the outer array get .joined by the delimiter.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jun 17 at 7:58









            CertainPerformanceCertainPerformance

            114k16 gold badges75 silver badges104 bronze badges




            114k16 gold badges75 silver badges104 bronze badges












            • I didn't know that if the argument was an array, it's wrapped in another array! That makes sense!

              – tkim90
              Jun 17 at 8:10






            • 1





              @tkim90 The arguments are always wrapped in an array, not just when the argument is an array.

              – Bergi
              Jun 17 at 18:42

















            • I didn't know that if the argument was an array, it's wrapped in another array! That makes sense!

              – tkim90
              Jun 17 at 8:10






            • 1





              @tkim90 The arguments are always wrapped in an array, not just when the argument is an array.

              – Bergi
              Jun 17 at 18:42
















            I didn't know that if the argument was an array, it's wrapped in another array! That makes sense!

            – tkim90
            Jun 17 at 8:10





            I didn't know that if the argument was an array, it's wrapped in another array! That makes sense!

            – tkim90
            Jun 17 at 8:10




            1




            1





            @tkim90 The arguments are always wrapped in an array, not just when the argument is an array.

            – Bergi
            Jun 17 at 18:42





            @tkim90 The arguments are always wrapped in an array, not just when the argument is an array.

            – Bergi
            Jun 17 at 18:42













            3














            In your code, you only have one argument in the first example, that being an array. Joining a single element will remove the brackets:






            var test = function() 
            var args = Array.prototype.join.call(arguments,"_");
            return args
            ;

            console.log(test([1,2,3])) // args = [[1,2,3]]
            console.log(test(1,2,3)) // args = [1,2,3]

            console.log([[1,2,3]].join('_'))
            console.log([1,2,3].join('_'))





            Another way to look at this is to provide another array as an argument to test():






            var test = function() 
            var args = Array.prototype.join.call(arguments,"_");
            return args
            ;

            console.log(test([1,2,3], [4,5,6]))








            share|improve this answer



























              3














              In your code, you only have one argument in the first example, that being an array. Joining a single element will remove the brackets:






              var test = function() 
              var args = Array.prototype.join.call(arguments,"_");
              return args
              ;

              console.log(test([1,2,3])) // args = [[1,2,3]]
              console.log(test(1,2,3)) // args = [1,2,3]

              console.log([[1,2,3]].join('_'))
              console.log([1,2,3].join('_'))





              Another way to look at this is to provide another array as an argument to test():






              var test = function() 
              var args = Array.prototype.join.call(arguments,"_");
              return args
              ;

              console.log(test([1,2,3], [4,5,6]))








              share|improve this answer

























                3












                3








                3







                In your code, you only have one argument in the first example, that being an array. Joining a single element will remove the brackets:






                var test = function() 
                var args = Array.prototype.join.call(arguments,"_");
                return args
                ;

                console.log(test([1,2,3])) // args = [[1,2,3]]
                console.log(test(1,2,3)) // args = [1,2,3]

                console.log([[1,2,3]].join('_'))
                console.log([1,2,3].join('_'))





                Another way to look at this is to provide another array as an argument to test():






                var test = function() 
                var args = Array.prototype.join.call(arguments,"_");
                return args
                ;

                console.log(test([1,2,3], [4,5,6]))








                share|improve this answer













                In your code, you only have one argument in the first example, that being an array. Joining a single element will remove the brackets:






                var test = function() 
                var args = Array.prototype.join.call(arguments,"_");
                return args
                ;

                console.log(test([1,2,3])) // args = [[1,2,3]]
                console.log(test(1,2,3)) // args = [1,2,3]

                console.log([[1,2,3]].join('_'))
                console.log([1,2,3].join('_'))





                Another way to look at this is to provide another array as an argument to test():






                var test = function() 
                var args = Array.prototype.join.call(arguments,"_");
                return args
                ;

                console.log(test([1,2,3], [4,5,6]))








                var test = function() 
                var args = Array.prototype.join.call(arguments,"_");
                return args
                ;

                console.log(test([1,2,3])) // args = [[1,2,3]]
                console.log(test(1,2,3)) // args = [1,2,3]

                console.log([[1,2,3]].join('_'))
                console.log([1,2,3].join('_'))





                var test = function() 
                var args = Array.prototype.join.call(arguments,"_");
                return args
                ;

                console.log(test([1,2,3])) // args = [[1,2,3]]
                console.log(test(1,2,3)) // args = [1,2,3]

                console.log([[1,2,3]].join('_'))
                console.log([1,2,3].join('_'))





                var test = function() 
                var args = Array.prototype.join.call(arguments,"_");
                return args
                ;

                console.log(test([1,2,3], [4,5,6]))





                var test = function() 
                var args = Array.prototype.join.call(arguments,"_");
                return args
                ;

                console.log(test([1,2,3], [4,5,6]))






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jun 17 at 7:57









                KobeKobe

                1,6472 silver badges19 bronze badges




                1,6472 silver badges19 bronze badges





















                    3














                    The first one, first argument is [1,2,3] which is joined with the second argument, which is nothing -> output is [1,2,3].toString().



                    Second call, it's actually joining all the 3 arguments, resulting in outputting 1_2_3.






                    share|improve this answer



























                      3














                      The first one, first argument is [1,2,3] which is joined with the second argument, which is nothing -> output is [1,2,3].toString().



                      Second call, it's actually joining all the 3 arguments, resulting in outputting 1_2_3.






                      share|improve this answer

























                        3












                        3








                        3







                        The first one, first argument is [1,2,3] which is joined with the second argument, which is nothing -> output is [1,2,3].toString().



                        Second call, it's actually joining all the 3 arguments, resulting in outputting 1_2_3.






                        share|improve this answer













                        The first one, first argument is [1,2,3] which is joined with the second argument, which is nothing -> output is [1,2,3].toString().



                        Second call, it's actually joining all the 3 arguments, resulting in outputting 1_2_3.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Jun 17 at 7:58









                        HRK44HRK44

                        1,0974 silver badges19 bronze badges




                        1,0974 silver badges19 bronze badges





















                            3














                            Because you're passing one argument which is an array - so it converts it to a string, then attempts to join it to the other arguments (there are none) so it just returns the string.






                            var test = function() 
                            var args = Array.prototype.join.call(arguments, "_");
                            return args
                            ;

                            console.log(test([1, 2, 3]));
                            console.log(test(1, 2, 3));





                            You can solve this by checking if there's only one argument passed.






                            var test = function() 
                            var args = arguments.length == 1 ? arguments[0].join("_") : Array.prototype.join.call(arguments, "_");
                            return args;
                            ;

                            console.log(test([1, 2, 3]));
                            console.log(test(1, 2, 3));








                            share|improve this answer



























                              3














                              Because you're passing one argument which is an array - so it converts it to a string, then attempts to join it to the other arguments (there are none) so it just returns the string.






                              var test = function() 
                              var args = Array.prototype.join.call(arguments, "_");
                              return args
                              ;

                              console.log(test([1, 2, 3]));
                              console.log(test(1, 2, 3));





                              You can solve this by checking if there's only one argument passed.






                              var test = function() 
                              var args = arguments.length == 1 ? arguments[0].join("_") : Array.prototype.join.call(arguments, "_");
                              return args;
                              ;

                              console.log(test([1, 2, 3]));
                              console.log(test(1, 2, 3));








                              share|improve this answer

























                                3












                                3








                                3







                                Because you're passing one argument which is an array - so it converts it to a string, then attempts to join it to the other arguments (there are none) so it just returns the string.






                                var test = function() 
                                var args = Array.prototype.join.call(arguments, "_");
                                return args
                                ;

                                console.log(test([1, 2, 3]));
                                console.log(test(1, 2, 3));





                                You can solve this by checking if there's only one argument passed.






                                var test = function() 
                                var args = arguments.length == 1 ? arguments[0].join("_") : Array.prototype.join.call(arguments, "_");
                                return args;
                                ;

                                console.log(test([1, 2, 3]));
                                console.log(test(1, 2, 3));








                                share|improve this answer













                                Because you're passing one argument which is an array - so it converts it to a string, then attempts to join it to the other arguments (there are none) so it just returns the string.






                                var test = function() 
                                var args = Array.prototype.join.call(arguments, "_");
                                return args
                                ;

                                console.log(test([1, 2, 3]));
                                console.log(test(1, 2, 3));





                                You can solve this by checking if there's only one argument passed.






                                var test = function() 
                                var args = arguments.length == 1 ? arguments[0].join("_") : Array.prototype.join.call(arguments, "_");
                                return args;
                                ;

                                console.log(test([1, 2, 3]));
                                console.log(test(1, 2, 3));








                                var test = function() 
                                var args = Array.prototype.join.call(arguments, "_");
                                return args
                                ;

                                console.log(test([1, 2, 3]));
                                console.log(test(1, 2, 3));





                                var test = function() 
                                var args = Array.prototype.join.call(arguments, "_");
                                return args
                                ;

                                console.log(test([1, 2, 3]));
                                console.log(test(1, 2, 3));





                                var test = function() 
                                var args = arguments.length == 1 ? arguments[0].join("_") : Array.prototype.join.call(arguments, "_");
                                return args;
                                ;

                                console.log(test([1, 2, 3]));
                                console.log(test(1, 2, 3));





                                var test = function() 
                                var args = arguments.length == 1 ? arguments[0].join("_") : Array.prototype.join.call(arguments, "_");
                                return args;
                                ;

                                console.log(test([1, 2, 3]));
                                console.log(test(1, 2, 3));






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Jun 17 at 7:58









                                Jack BashfordJack Bashford

                                26.7k6 gold badges24 silver badges51 bronze badges




                                26.7k6 gold badges24 silver badges51 bronze badges





















                                    3














                                    In the first example you are not calling .join on the array but on arguments. That variable will be populated with an array-like object that has an array as first index, in essence, you are calling the equivalent of:






                                    let myArguments = [[1, 2, 3]];

                                    console.log(myArguments.join("_"));





                                    instead of what you do (the equivalent of) in the second example:






                                    let myArguments = [1, 2, 3];

                                    console.log(myArguments.join("_"));








                                    share|improve this answer



























                                      3














                                      In the first example you are not calling .join on the array but on arguments. That variable will be populated with an array-like object that has an array as first index, in essence, you are calling the equivalent of:






                                      let myArguments = [[1, 2, 3]];

                                      console.log(myArguments.join("_"));





                                      instead of what you do (the equivalent of) in the second example:






                                      let myArguments = [1, 2, 3];

                                      console.log(myArguments.join("_"));








                                      share|improve this answer

























                                        3












                                        3








                                        3







                                        In the first example you are not calling .join on the array but on arguments. That variable will be populated with an array-like object that has an array as first index, in essence, you are calling the equivalent of:






                                        let myArguments = [[1, 2, 3]];

                                        console.log(myArguments.join("_"));





                                        instead of what you do (the equivalent of) in the second example:






                                        let myArguments = [1, 2, 3];

                                        console.log(myArguments.join("_"));








                                        share|improve this answer













                                        In the first example you are not calling .join on the array but on arguments. That variable will be populated with an array-like object that has an array as first index, in essence, you are calling the equivalent of:






                                        let myArguments = [[1, 2, 3]];

                                        console.log(myArguments.join("_"));





                                        instead of what you do (the equivalent of) in the second example:






                                        let myArguments = [1, 2, 3];

                                        console.log(myArguments.join("_"));








                                        let myArguments = [[1, 2, 3]];

                                        console.log(myArguments.join("_"));





                                        let myArguments = [[1, 2, 3]];

                                        console.log(myArguments.join("_"));





                                        let myArguments = [1, 2, 3];

                                        console.log(myArguments.join("_"));





                                        let myArguments = [1, 2, 3];

                                        console.log(myArguments.join("_"));






                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Jun 17 at 7:59









                                        VLAZVLAZ

                                        6,8425 gold badges25 silver badges37 bronze badges




                                        6,8425 gold badges25 silver badges37 bronze badges





















                                            3














                                            The result is different, because arguments is different.



                                            On the first call (test([1,2,3]), you have one argument which is an array.
                                            On the second call, you have 3 arguments, each one being a number.



                                            Array.prototype.join is meant to be called over arrays. It will stringify each of the items in the array.



                                            In you your first case, your arguments "array" has only one member, which is an array itself. This argument will be stringfied. An array stringfied becomes exactly what is logged in your code.






                                            share|improve this answer





























                                              3














                                              The result is different, because arguments is different.



                                              On the first call (test([1,2,3]), you have one argument which is an array.
                                              On the second call, you have 3 arguments, each one being a number.



                                              Array.prototype.join is meant to be called over arrays. It will stringify each of the items in the array.



                                              In you your first case, your arguments "array" has only one member, which is an array itself. This argument will be stringfied. An array stringfied becomes exactly what is logged in your code.






                                              share|improve this answer



























                                                3












                                                3








                                                3







                                                The result is different, because arguments is different.



                                                On the first call (test([1,2,3]), you have one argument which is an array.
                                                On the second call, you have 3 arguments, each one being a number.



                                                Array.prototype.join is meant to be called over arrays. It will stringify each of the items in the array.



                                                In you your first case, your arguments "array" has only one member, which is an array itself. This argument will be stringfied. An array stringfied becomes exactly what is logged in your code.






                                                share|improve this answer















                                                The result is different, because arguments is different.



                                                On the first call (test([1,2,3]), you have one argument which is an array.
                                                On the second call, you have 3 arguments, each one being a number.



                                                Array.prototype.join is meant to be called over arrays. It will stringify each of the items in the array.



                                                In you your first case, your arguments "array" has only one member, which is an array itself. This argument will be stringfied. An array stringfied becomes exactly what is logged in your code.







                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited Jun 17 at 8:25

























                                                answered Jun 17 at 7:59









                                                Walter MacambiraWalter Macambira

                                                1,89313 silver badges25 bronze badges




                                                1,89313 silver badges25 bronze badges



























                                                    draft saved

                                                    draft discarded
















































                                                    Thanks for contributing an answer to Stack Overflow!


                                                    • Please be sure to answer the question. Provide details and share your research!

                                                    But avoid


                                                    • Asking for help, clarification, or responding to other answers.

                                                    • Making statements based on opinion; back them up with references or personal experience.

                                                    To learn more, see our tips on writing great answers.




                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function ()
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56626979%2fhow-does-join-produce-different-results-depending-on-the-arguments%23new-answer', 'question_page');

                                                    );

                                                    Post as a guest















                                                    Required, but never shown





















































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown

































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown







                                                    Popular posts from this blog

                                                    Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

                                                    Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

                                                    Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림