# Other Languages > jQuery >  Need code explanation

## Apparrel

Can someone please explain this code to me:

Why does the funtion call below take in two arguments:

type = Spry.Widget.Utils.firstValid(type, "none");

While it was defined without any argument:

Spry.Widget.Utils.firstValid = function() {
	var ret = null;
	for(var i=0; i<Spry.Widget.Utils.firstValid.arguments.length; i++) {
		if (typeof(Spry.Widget.Utils.firstValid.arguments[i]) != 'undefined') {
			ret = Spry.Widget.Utils.firstValid.arguments[i];
			break;
		}
	}
	return ret;
};

Any help and thought wellcomed. 

Thanks.

----------


## SambaNeko

Just part of how Javascript works; you're not required to specify all (or any) of a function's arguments.  If you write a function that's expected to have a consistent number of arguments, then it's good practice to (and simpler to work with if you) specify them.  But if your function may accept a variable number of arguments, then you might use something like what you've got there; all functions have an "arguments" object by which you can access the passed arguments by numeric index.

It's not an approach you should use without good reason though.

----------


## Apparrel

Thanks SambaNeko, u've just saved me 3 days of wondering. Thank you soo much.

----------


## penagate

It's not necessary to qualify arguments:


```
Spry.Widget.Utils.firstValid = function() {
	var ret = null;
	for(var i=0; i<arguments.length; i++) {
		if (typeof(arguments[i]) != 'undefined') {
			ret = arguments[i];
			break;
		}
	}
	return ret;
};
```

----------


## penagate

another improvement:


```
Spry.Widget.Utils.firstValid = function() {
	for (var i in arguments)
		if (typeof arguments[i] !== 'undefined')
			return arguments[i];
};
```

Not really sure of the value of this function, to be frank.

----------

