Functions can accept arguments, which are used as inputs for the function.The inputs are acted upon and the results are returned to the parent function via return value.
Functions are used when some task needs to be done repeatedly within a program. Rather than writing the same code over and over, you can use a function and call it when required to perform the task.
A good example is a CellPhone, you can press a button to make a call, use an app to play a game, listen to music. You care for results and not how they are obtained, like a blackbox.
A function is defined by using the keyword function followed by the name of the function and a set of parentheses to hold parameters or values to be recieved by the function.
The function can be called when required by using the function name followed by the argument enclosed within parentheses(seperated by comma, in case of multiple arguments) .
Arguments can be passed to the function by enclosing the values in a parentheses after the function name and sent as a comma separated list of arguments while calling the function.
The arguments recieved as parameters by the recieving function and are stored in local variables, but as soon as the function ends the variable disappears
The scope of the variables defines where the variable can be used in the program(i.e its visibility) .
The variables declared outside the function have a global scope, i.e they can be used and manipulated any where in the program.
The variables declared using the keyword var within a function has a local scope, i.e they can be used and manipulated within the function only.