Jump to content

Function parameters, would you explain ? (solved)


virtualw3schools

Recommended Posts

Normally, the "var" keyword is required to make it explicit that you want a new variable, rather than reusing one from a higher/global scope.The line

function product(A, 

is a function declaration.A function declaration is not allowed to reuse variables, since the value of those reused variables would only be known when you call the function later on, thus rendering the function uncompilable (=> REALLY slow). Because of this, the "var" keyword is not required for specifying parameters, and is in fact completely eliminated from the syntax at that point, to make JavaScript simpler.

Link to comment
Share on other sites

A parameter is just like a variable, except that its value is determined when you call the function.For example,

function product(A,{return A*B;}

defines a function called "product" that takes two parameters. With the part

(A,

we're saying that within the function, the variable "A" will refer to the first parameter, and "B", to the second one.If later in the code you have

product(2,3)

that would be you calling the function with two values - one for each parameter. The first one being 2, and the second one being 3.Since the function internally refers to the first parameter as "A", and the second "B", the part

return A*B;

becomes equivalent to

return 2*3;

which, of course, results in 6.

Link to comment
Share on other sites

A parameter is just like a variable, except that its value is determined when you call the function. For example,
function product(A,{return A*B;}

defines a function called "product" that takes two parameters. With the part

(A,

we're saying that within the function, the variable "A" will refer to the first parameter, and "B", to the second one. If later in the code you have

product(2,3)

that would be you calling the function with two values - one for each parameter. The first one being 2, and the second one being 3. Since the function internally refers to the first parameter as "A", and the second "B", the part

return A*B;

becomes equivalent to

return 2*3;

which, of course, results in 6.

Oh thank you :good:, that explanation was really helpful! Now I can continue :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...