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 where- sumis 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 argument- 2is written to the first parameter- numberFirst, argument- 5is written to parameter- numberSecond. It’s important to observe the parameter order when calling the function in order to avoid errors that are not obvious.
Continue