“arguments” is another keyword JavaScript engine create during the creation of execution context, arguments contains a list of all the values of all the parameters that passed to a function.
argument is an array-like object, it doesn’t has all the features of JavaScript array
1 2 3 4 5 6 7 8 9 10 11 12 13 |
function MyFunc(arg1, arg2, arg3){ console.log(arguments); // [] console.log(typeof(arguments)); // Object if(arguments.length === 0){ return; } console.log(arguments[0]); } MyFunc(); |
“arguments” will become deprecated in the future, the new thing is called spread
1 2 3 |
function myFunc(arg1, arg2, arg3, ...other){ // avaliable in the future... } |