This forum is now read-only. Please use our new forums at discuss.codecademy.com.

1116 points
260d988d8c391d55ed9773bed02c2987?s=140&d=retro
Submitted by
swali1
almost 4 years ago

What is function call?

how do you call a function in javascript.what is the syntax and a example please.

thanks


1 vote

permalink

You call the function by typing its name and putting a value in parentheses. This value is sent to the function's parameter.

e.g.

var firstFunction = function(firstParameter)
{
console.log("Print the " + firstParameter;
}
firstFunction("string as it's shown.");

In this example the function's name is firstFunction
The parameter's name is firstParameter

We call the function firstFunction("string as it's shown.");

This sends the string "string as it's shown." to the function and the parameter firstParameter takes it's value.

Now the code inside the function actual reads

"Print the " + "string as it's shown.";

Does that make sense?

100 points
A8f715d482d6949dc44abcb224d11297?s=140&d=retro
Submitted by
Smoshy16_552fadf0937676bee600020d_de
almost 4 years ago

4 Comments

260d988d8c391d55ed9773bed02c2987?s=140&d=retro swali1 almost 4 years ago

yes..Thanks.only the last bit got ehh..."Print the " + "string as it's shown."; was a little tricky..sinmce the elemts in the example you gave were first parameter ,first function.i mean not easy to understand elements.Anyways good example.
Thanks

260d988d8c391d55ed9773bed02c2987?s=140&d=retro swali1 almost 4 years ago

why is function not called before the variable declaration?

260d988d8c391d55ed9773bed02c2987?s=140&d=retro swali1 almost 4 years ago

Primitive parameters (such as a number) are passed to functions by value; the value is passed to the function, but if the function changes the value of the parameter, this change is not reflected globally or in the calling function.

260d988d8c391d55ed9773bed02c2987?s=140&d=retro swali1 almost 4 years ago

what does the above sentence mean?