Issue with arguments object

I am having a issue using the arguments object.

I am working on the Arguments Optional challenge and am trying to access the length of my arguments input.

const addTogether = (x, y) => {
  if (arguments.length == 1) {
    return typeof x != "string" ?  y => x + y : undefined
  if (arguments.length == 2) {
    return typeof y != 'string' ? x + y : undefined;
addTogether(2, 3);

When I try to console.log() my arguments I get the following:

{ '0': 
   { tryEntries: [ [Object], [Object], [Object] ],
     prev: 10,
     next: 0,
     _sent: undefined,
     sent: undefined,
     done: false,
     delegate: null,
     method: 'next',
     arg: undefined } }

No matter what I do I always get this same object. I tried arguments[0], arguments.length (always returns 1) and [...arguments] and I still cannot get a list of all the values.

Any ideas to what could be causing this?

Edit: My goal is to create a array with the parameters [x, y];

I also just noticed my code won’t work as intended if one of the values is a a array ([x] or [y] as per the tests). Will adjust when I get their.

From MDN,

The arguments object is a local variable available within all non-arrow functions
The arguments object - JavaScript | MDN

That’s why you keep getting that object, and if you tried the same thing as a normal function then your code will work.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.