Posted By

1man on 12/02/07


object function arguments

Versions (?)

Who likes this?

3 people have marked this snippet as a favorite


Accessing Arguments Using the Arguments Object

 / Published in: JavaScript

Every function has an object called the arguments object. This is an object that contains all the arguments that were passed to the function. The example below shows how to access these. Very rarely used but useful to know. Note: it may look like an array, but it's better to think of it as an object with numbered properties.

  1. function containerScope(){
  2. var a = [];
  3. var b = {};
  4. var c = true;
  5. var d = 22;
  6. function argumentsObject(a, b, c, d){
  7. console.log(arguments.length);
  8. console.log(arguments[0]);//Array
  9. console.log(arguments[1]);//Object
  10. console.log(arguments[2]);//true
  11. console.log(arguments[3]);//22
  12. arguments[3] = 55;//I have now changed d as well!
  13. console.log(arguments[3]);
  14. console.log(d);
  15. }
  16. argumentsObject(a, b, c, d);
  17. }

Report this snippet  

You need to login to post a comment.