Adventures of brushing up after a break

Getting back in the swing of things after a break and have a question concerning parameters/arguments in the following example.

function sym(args) {
  console.log(args); // [1, 2, 3]
}

sym([1, 2, 3], [5, 2, 1, 4]);

So I was wanting to get the arguments passed to the sym function and tried so by logging args to the console which outputs the first array.

I remembered I could log the arguments passed to the function with console.log(arguments) and then realized the reason console.log(args) was only giving me the first array because sym([1, 2, 3], [5, 2, 1, 4]) was passing two parameters to the sym function and if I edited the function to look like this:

function sym(args1, args2) {...}

I could then access them that way as well as using arguments, although using arguments will be better since I will be tested with more than two arguments passed to that function.

This is for the Symmetric Difference challenge and my question might be nitpicky but… Why is the function they give you written like that with the args parameter? It seems it’s not even needed since I will be using the arguments object to access the parameters passed to the function.

I just glanced at the Guide for this challenge and it looks like the initial line to declare the function IS written without any parameters function sym() {...} .

I guess since I took a break I was holding too much weight to the function they wrote to get you started with the challenge.

Well I answered my own question while typing this, thanks for reading! :grinning::gun:

1 Like