Return to Snippet

Revision: 4366
at December 2, 2007 06:50 by 1man


Initial Code
function containerScope(){
	var a = [];
	var b = {};
	var c = true;
	var d = 22;
	function argumentsObject(a, b, c, d){
		console.log(arguments.length);
		console.log(arguments[0]);//Array
		console.log(arguments[1]);//Object
		console.log(arguments[2]);//true
		console.log(arguments[3]);//22
		arguments[3] = 55;//I have now changed d as well!
		console.log(arguments[3]); 
		console.log(d);
	}
	argumentsObject(a, b, c, d);
}

Initial URL


Initial Description
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.

Initial Title
Accessing Arguments Using the Arguments Object

Initial Tags
object, function

Initial Language
JavaScript