Home / Advanced JavaScript Tutorial / Creating Robusts Functions |
CodingForums Jump to...
- CSS Drive
- JavaScript Menus - PHP Resources - Hotels & Vacations - Java Online Casinos - Web hosting Search |
The arguments array is a secretive little object that exists inside every function. As you effortlessly pass in parameters into a function, the arguments array is working hard not only storing the values of these parameters into one of its array element, but jotting down the total number of parameters passed as well. This is realized through the following syntax: functionname.arguments.length="contains the total number of parameters" Note: The functionname proceeding the arguments array is optional. You're baffled, and I don't blame you. The best way to understand this object is to see it at work, so lets do just that. The below's a function that accepts three parameters. Lets use the arguments array to expose that, and more! function mynumbers(firstword, secondword, thirdword){
The above's a basic function that accepts three parameters. Lets call it now, and see what the arguments array has to offer:
What's the big deal with this example, you say. Plenty! Sure, its obvious from simply looking at the function what the total number of parameters is, and the values of each parameter, but we never could tell by using JavaScript codes. Now, we could, through the arguments array of each function. -Tutorial introduction |
http://javascriptkit.com |