Functions - The Basics

Author: Shaunk...

Over the past few months I've been predominantly focussing on developing my Javascript and jQuery competence.

Functions are a very powerful and efficient way of grouping, executing and reusing code. They're a standard part of many scripting and programming languages including Javascript, Actionscript and PHP so getting familiar with the syntax and how they work can be very rewarding.

There are two stages to any function; declaration and invocation. Imagine this to be an author-reader relationship, the latter utilising information created by the former. Highly effective as you only need one author to satisfy millions of readers.

The basic structure of a function declaration is as follows.


function nameOfFunction(listOfVariableNames) {
code to be executed goes here
}

And to invoke (or call) a function you would place the following code wherever required:

nameOfFunction();

Or for functions with variable parameters you would call as follows:

nameOfFunction(listOfVariables);

Pretty simple. This is all you really need to know to start using functions.

They're are further ways of achieving similar results and you can also assign functions to variables in some languages. See one of these links for more information about a specific language.

Javascript
| Actionscript | PHP

 

0 Response to “Functions - The Basics”

Leave a Reply