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