Function Parameters
Functions can take in external information in the form of variables or directly through function parameters
. They are specified inside the parenthesis after the function name. Multiple parameters can be separated by commas.
Function parameters are given a variable name inside the parenthesis during function declaration. The desired values are passed when the function call is invoked. Below code block demonstrate some examples of specifying function parameters and calling functions with parameters.
1function func1(name) {
2 console.log("Hello I am " + name);
3}
4
5function add(a, b, c) {
6 let d = a + b + c;
7 console.log("Sum of a, b, and c is: " + d);
8}
9
10func1("Beth");
11add(2, 3, 4);
Note: Here the variable
d
is of typeint. We use
str(d)to convert the type of variable
dfrom
intto
string, as string concatenation only works with two variables of type
string. Concatenation of
stringand
int` would generate an error.