This forum is now read-only. Please use our new forums! Go to forums
how do you call a function in javascript.what is the syntax and a example please.
thanks
Answer 557acf299113cbe852000022
1
vote
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 firstFunctionThe 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?
4 comments
over 8 years
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
over 8 years
why is function not called before the variable declaration?
over 8 years
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.
over 8 years
what does the above sentence mean?
Popular free courses
Free Course
Learn SQL
Beginner friendly,
4 Lessons
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.
Language Fluency
Free Course
Learn JavaScript
Beginner friendly,
11 Lessons
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
Language Fluency
Free Course
Learn HTML
Beginner friendly,
6 Lessons
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.
Language Fluency