Anotomy Of A Function
The basic philosophy of function is divide and conquer by which a complicated tasks are successively divided into simpler and more manageable
tasks which can be easily handled. A program can be divided into smaller subprograms that can be developed and tested successfully.
A function therefore is a complete and independent program which is used (or invoked) by the main program or other subprograms.
A subprogram receives values called arguments from a calling program, performs calculations and returns the results to the calling program.
Packages of Algorithms
Functions are packages of algorithms, which implies that they have three parts:
- Name
- Parameter
- Definition
Together these parts form the function declaration. Many programs require that a specific function is repeated many times instead
of writing the function code as many timers as it is required we can write it as a single function and access the same function again
and again as many times as it is required. This helps avoid writing redundant program code of some instructions again and again.
Name
Name; is the identifier of the function and it is common to use it to describe what the function does. Although computers would be happy with any
unique name that does not conflict with the programming protocol, it is a better practice to assign variable names that will be meaningful and friendly to humans.
For instance, We will want suggestive variable names to remind ourselves of what computation the functions perform.
Names in JavaScript are usually, identifiers that are they begin with a letter, use any mix of letters, number, and underscores. There is a limitation on what these names can be
It is conventional to avoid the use of capital letters in variable names. These are used for names of constants.
The rules governing variable names also apply to the names of functions
e.g. <..name..> (
Examples of legal variable names
- x
- result
- outfile
- bestyet88
Statement
The easiest example of an expression is in the assignment statement. An expression is evaluated, and the result is saved in a variable. A simple example might look like.
Parameter: these are the values that the function will compute on, the input to the functions E.g. y = (m * x) + c
This assignment will save the value of the expression in variable y.
Definition
Definition: the function definition is the algorithm written in a programming language, a function definition follows the language's general riles for program statement.Because the function definition is computing an algorithm a precise and systematic method for producing a specified result, there must be some way to say what the result is,
that is, some way to give the answer.
Types of functions
A function may belong to any one of the following categories:
- Functions with no arguments and no return values.
- Functions with arguments and no return values.
- Functions with arguments and return values.