Seek and Destroy ES6 arguments output to console

Hi there fine folks,

I just returned to do some revision and re-visit some challenges starting with ‘Intermediate Algorithm Scripting’ because they were really hard!

Going over my notes, I realised that I had used the ES5 syntax to write functions so thought it reasonable to re-write using the ES6 syntax. However! I’m having a bit of a problem with the arguments object in the ‘Seek and Destroy’ challenge:

function destroyer(arr) {
  console.log(arguments)
  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);

this outputs the arguments object as expected to the console like this:

{ '0': [ 1, 2, 3, 1, 2, 3 ], '1': 2, '2': 3 }

However, when I write the same function in ES6 syntax like this:

const destroyer2 = (arr) => {
  console.log(arguments)
}
destroyer2([1, 2, 3, 1, 2, 3], 2, 3);

I get this output :

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

What on earth is going on??? I know that the arguments object is a JSON format obect and I understand the output from the ES5 function, but what is this? Can we not work with the arguments object in the same way in ES6?

Please help, I’m having a bad day!

LT

Read the bulleted list under Differences & Limitations very closely.

1 Like

Oh! Really?

I think this answers my question from the MDN docs link you posted:

  • Does not have arguments , or new.target keywords.

Thank you @bbsmooth :wink: I could have been stuck on that anomaly for a long while if it wasn’t for your reply, which is much appreciated.

Seriously though, I’ve heard vetran JS coders slating ES6 in the past, and for the life of me I can’t see why they would do that!

Thanks again.

LT