Maximizing the number of parameters through JavaScript

Asked By 0 points N/A Posted on -
qa-featured

In using a Java Script application, how do I create robust functions that can accept any number of parameters?

SHARE
Best Answer by Sharath Reddy
Answered By 0 points N/A #116009

Maximizing the number of parameters through JavaScript

qa-featured

Hi Jessica,

Inside every function, we have an object called an arguments array. It is this object that stores and calculates how many parameters you are passing on to the function. This array is present in every function even if we do not declare this or demand it.

With the help of the arguments array and some minor changes in defining the functions we create, we can make a function that accepts any number of parameters.

Instead of the normal function with parameters,

function hello(x,y,z){
 
}

We create a function as so:

function hello(){
 
}

See that the function we created above no longer has any parameters. Then we just create a loop inside the function we made:

function hello(){
for (x=0;x<hello.arguments.length;x++)
//do whatever
}



Thanks Jessica, hope this would be of help.

 

Best Answer
Best Answer
Answered By 590495 points N/A #116010

Maximizing the number of parameters through JavaScript

qa-featured

If you are a beginner and wants to learn about JavaScript programming, one way of learning this yourself is through an online tutorial website like JavaScript Tutorial. This site gives an excellent tutorials and examples on different web programming languages like JavaScript, PHP, HTML, HTML5, and so on. Just visit the site to start your lesson.

JavaScript, on the other hand, is the scripting language of the web that is being used by billions of web pages around the world. Web sites use this to add style, functionality, validate forms, communicate with the server, and more. You can really use it on whatever purpose it is you want. An example of a JavaScript command is the “document.write(‘’)”. It is used to display or print something on the page. Here is an example for this command that will display the text “Hello! How are you doing?”:

<script type="text/javascript">
document.write(‘Hello! How are you doing?’)
</script>

Output:

Hello! How are you doing?

Here’s another example using it to display a link. This will display the link for this website.

<script type="text/javascript">
document.write(‘<a href=’+’”’+’ https://www.techyv.com’+’”’+’>TechyV.com</a>’)
</script>

Output:

TechyV.com

Answered By 0 points N/A #116011

Maximizing the number of parameters through JavaScript

qa-featured

Each of your comments is just great. Sharath, you are right, I am a beginner and also want to learn about JavaScript programming. So by reading your comments and visiting your provided links and website, I have understood the useful information you provided. Also, your easy example helped me to understand more the primary stage of JavaScript. Following your advice now day by day, I am able to develop my programming knowledge. Thanks one more time to you and Techyv as well for publishing this great solution.

Related Questions