answersLogoWhite

0

What is function parameter or argument in JavaScript?

Updated: 8/19/2019
User Avatar

Wiki User

12y ago

Best Answer

It is an input to the function. You can use them to apply the same operation to different inputs. You create a function with parameters by putting the parameters in a comma separated list in the parentheses after a function name. For example:

function myFunctionWithParameters(parameter1,parameter2,parameter3)

{

//Code to execute

}

Within the code, you refer to them as if they were variables that were assigned to the parameter name. For example:

function squareNumber(myNumber)

{

return myNumber*myNumber;

}

Parameter names follow the same rules as variable names: they cannot start with a number, they cannot have a dot in them, etc.

To call a function with parameters, you simply put the values of the parameters within the parentheses. You can also use variable names to refer to the value to pass to the function. For example:

var theNumber=10;alert(squareNumber(theNumber)); //Shows alert box displaying 100

Note that parameters can be passed in as any type. For example:

function add(a,b)

{

return a+b;

}

alert(add(1,2)); //Shows alert box displaying 3

alert(add("foo","bar")); //Shows alert box displaying foobar

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is function parameter or argument in JavaScript?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is a variable that is used within a function?

If the variable is declared within the function body, it is a local variable, one that is local to the function. Local variables fall from scope when the function returns, they are only accessible within the function. However, local variables can be returned by value, which creates an automatic variable that is returned to the caller. If the caller does not store the return value, the automatic variable falls from scope when the expression containing the function call ends. However, the expression may evaluate the return value without storing it. Note that functions cannot return local variables by reference since the local variable falls from scope when the function returns. If the variable is passed as an argument to the function, then the variable is a parameter of the function. Arguments may be passed by value or by reference, depending upon the function signature. Passing by value means the function parameter is a copy of the argument (if the argument is an object, the object's copy constructor is invoked automatically). Thus any changes made to the parameter within the function are not reflected in the argument that was originally passed, and the parameter will fall from scope when the function returns. However, the value of the parameter can be returned as previously explained. Passing by reference means the function parameter refers directly to the argument that was passed. Thus any changes made to the parameter are reflected in the argument. Parameters that are declared as constant references assure the caller that the reference's immutable members will not be altered by the function. If the parameter is a non-const reference but the caller does not wish changes to be reflected in the argument, the caller should pass a copy of the argument instead.


Why it is not possible to pass a function as an argument to another function in c?

It is quite possible. A well-known example is the fourth parameter of qsort.


Javascript function for the difference between 2 numbers?

This function will accept two parameters and return the difference between the first and second parameter. function diffBetween ( a, b ) { return a-b; } //end diffBetween


How do you write functions in JavaScript?

There are several methods, all leading to a similar place. The first is to simply declare a function using the function keyword: function ourFunction(args){} The second is to assign a variable as a function: var ourFunction = function(args) {}; And the third (commonly used in JavaScript frameworks, or when function is being passed as a parameter) is to just use an anonymous function. window.onload = function(args) {};


What is meant by arguments in c?

Arguments appear in functions and in function calls. Arguments passed to a function are known as actual arguments. The arguments used by the function are known as the formal arguments. In C, all arguments are passed by value, such that the formal argument is a copy of the actual argument.


What is the difference between parameters and arguments in VB?

In programming languages, a parameter and an argument are the same thing; there is no actual difference between the two. Although a few languages do differentiate between an actual argument and a formal argument by calling one a parameter and the other an argument (or vice versa), the terms are universally interchangeable. That is; there is no single definition that applies to any one language, including Visual Basic. The language may have a convention, but there's no reason to follow that convention. Personally, I prefer the term argument and use the terms formal argument and actual argument whenever I need to specifically differentiate one from the other. In this way I can refer to them in a consistent but language-agnostic manner. Only a Pedant would argue that the terms parameter and argument have a specific meaning to a specific language, even when the creators of that language use the terms interchangeably themselves. To clarify, an actual argument is the argument being passed to a function while a formal argument is the argument that is used by the function. The two will always have the same value, but they are not the same argument. For instance, consider the following function definition: f (int a) { print a*2 } Whether we regard 'a' as being a parameter or an argument is immaterial -- it is a formal argument or formal parameter, whichever you prefer. The meaning is clarified by using the word "formal". Now consider the calling code: b = 42 f (b) Here, b is the actual argument (or actual parameter) being passed to the function f. Note that a and b are not the same variable or reference. That alone means there is no reason to differentiate them; the meaning of argument or parameter is implied by the context alone. It doesn't matter whether the function uses pass by value or pass by reference semantics. When passing arguments by value, a is simply a copy of b (independent variables with the same value). When passing by reference, a refers to the same memory address as b (a is an alias for b). In either case, the function uses the formal argument named a while the calling code uses the actual argument named b. In other words, the names are only accessible from within the scope in which they are declared, even if they refer to the same memory address. Of course, a function may pass one of its formal arguments to another function. Thus with respect to the calling function, its formal argument becomes an actual argument to the function being called.


Does a function always require a parameter?

No. For example, function getpid never requires a parameter.


What is argument in c plus plus?

If this is a homework assignment, please consider trying to answer it yourself first, otherwise the value of the reinforcement of the lesson offered by the assignment will be lost on you.An argument (or parameter) in C or C++ is a special variable that is passed to a function when it is called. In the example...float sin(float x);... the x is an argument. Within the body of the function, x refers to the copy of the caller's argument that was passed to the function.


In python are actual and formal parameters matched up by position or name?

When we invoke a function, we pass the actual arguments in the same order specified by the function's formal arguments, thus it is the relative position that determines how they are matched. Note that actual parameter names are within the scope of the calling code while formal parameter names are scoped to the function in which they are declared. The calling code has no access to the formal argument names, and the function may or may not have access to the actual argument names. Python uses the pass-by-object paradigm: if the object being passed is immutable, then it is passed by value (the formal parameter is assigned a copy of the object's value), otherwise it is passed by reference (in which case the formal argument becomes an alternative name for the actual argument).


Can you have in-out parameter in a function if not then why?

because function have return sts thatway it is not necessary out parameter to function


In dos what is the function of a parameter?

A parameter is a command-line switch or an argument to a function. We use parameters to specify the input variables for the commands or functions we invoke. For instance, when we want to list the contents of a directory or folder, we have to pass the directory or folder path to the appropriate command so that it knows which directory or folder to process.


How do you transfer VBScript variable value to JavaScript function as parameter in ASP?

An example answer can be found: http://www.planet-source-code.com/URLSEO/vb/scripts/ShowCode!asp/txtCodeId!8503/lngWid!4/anyname.htm