A function is a bunch of code that can be reused in order to carry out some process. In order to make it do what you want it to do, you need to call it. Calling a function simply means that your computer will run your code to get the desired outcome.
Here is an example:
function EndConversation ( ) {
alert (“Goodbye.”);
}
EndConversation ( );
Another component of functions are returning data. When we are writing code, we can make functions that return data. In order to do this, you need the return key word. This key word exists the function and gives us a value it gives us data. All functions return a value.
Here is an example:
function additionFormula (x,y) {
var result = x + y ;
return result;
}
var sumOf1And2 = additionFormula(1,2);
sumOf1And2;
3
In the end, functions are here to help us. It makes our code less complex and more maintainable. I’m still trying to wrap my head around the whole concept, I’m at understanding when practicing than when I’m explaining it.
Your examples were really effective for helping me to understand your explanations.