HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-03-09
1 <p>Function example.</p>
1 <p>Function example.</p>
2 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 14<p>In this example:</p>
2 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 14<p>In this example:</p>
3 <ul><li>calculateSum is the name you can use to call the function.</li>
3 <ul><li>calculateSum is the name you can use to call the function.</li>
4 <li>numberFirst, numberSecond are function parameters.</li>
4 <li>numberFirst, numberSecond are function parameters.</li>
5 <li>return sum; is the place in the code where sum is returned and where we exit the function.</li>
5 <li>return sum; is the place in the code where sum is returned and where we exit the function.</li>
6 <li>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 2 is written to the first parameter numberFirst, argument 5 is 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.</li>
6 <li>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 2 is written to the first parameter numberFirst, argument 5 is 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.</li>
7 </ul><a>Continue</a>
7 </ul><a>Continue</a>