Skip to content

Instantly share code, notes, and snippets.

@ShivrajRath
Last active August 29, 2015 14:13
Show Gist options
  • Save ShivrajRath/e1cb02fa573f0d5a3c4a to your computer and use it in GitHub Desktop.
Save ShivrajRath/e1cb02fa573f0d5a3c4a to your computer and use it in GitHub Desktop.
Curious case of JavaScript function arguments
/**
* Running the array reverse function on arguments object
*/
function reverseArgs(){
return Array.prototype.reverse.call(arguments);
}
reverseArgs(12,34,55);
// OUTPUT
// [55, 34, 12]
/**
* Running the array join function on arguments object
*/
function argsJoin(){
return [].join.apply(arguments,["~"]);
}
argsJoin(12,33,44);
// OUTPUT
// "12~33~44"
/**
* arguments object just looks like an index Array, it's not an Array object
*/
function argsExp(){
return arguments instanceof Array;
}
argsExp();
//OUTPUT
// false
/**
* arguments object have an array like notation
*/
function argsExp(){
return arguments;
}
argsExp("one", "two", "three");
// OUTPUT
// ["one", "two", "three"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment