Summary of “Functions”. Part 1
Function example.
var calculateSum = function (numberFirst, numberSecond) {
var sum = numberFirst + numberSecond;
return sum;
};
calculateSum(); // Will return NaN
calculateSum(2); // Will return NaN
calculateSum(2, 5); // Will return 7
calculateSum(9, 5); // Will return 14In this example:
calculateSumis the name you can use to call the function.numberFirst,numberSecondare function parameters.return sum;is the place in the code wheresumis returned and where we exit the function.calculateSum(2, 5);are arguments that are transferred in the function when it is called. The order of the arguments is the same as for the function parameters. The first argument2is written to the first parameternumberFirst, argument5is written to parameternumberSecond. It’s important to observe the parameter order when calling the function in order to avoid errors that are not obvious.
Continue