1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-02 22:58:01 +00:00
Files
til/javascript/accessing-arguments-to-a-function.md
jbranchaud 0d0a92011f Fix a typo
2016-03-22 22:32:54 -05:00

685 B

Accessing Arguments To A Function

The arguments object is available within any JavaScript function. It is an array-like object with all of the arguments to the function. Even if not all of the arguments are referenced in the function signature, they can still be accessed via the arguments object.

function argTest(one) {
  console.log(one);
  console.log(arguments);
  console.log(arguments[1]);
}

argTest(1);
// 1
// [1]
// undefined

argTest(1, 'two', true);
// 1
// [1,'two',true]
// 'two'

See the Arguments object docs on MDN for more details.

h/t Dorian Karter