Categories

function

Amina Freinger abril 1, 2016
No votes yet.
Please wait...

Functions are "self-contained" modules of code that accomplish a specific task. Functions usually "take in" data, process it, and "return" a result. Once a function is written, it can be used over and over and over again. Functions can be "called" from the inside of other functions.

The main functions features are:

  • They allow us to conceive of our program as a bunch of sub-steps. Each sub-step can be its own function. When any program seems too hard, just break the overall program into sub-steps.

  • They allow us to reuse code instead of rewriting it.

  • Functions allow us to keep our variable namespace clean (local variables only "live" as long as the function does). In other words, function_1 can use a variable called "i", and function_2 can also use a variable called "i" and there is no confusion. Each variable "i" only exists when the computer is executing the given function.

  • Functions allow us to test small parts of our program in isolation from the rest. This especially can be useful in C, Java, ActionScript, etc.

Different programming languages handle different functions. For example, in JavaScript a function is a procedure or a set of statements that performs a task or calculates a value. To use a function, you must define it somewhere in the scope from which you wish to call it. A function definition (also called a function declaration) consists of the function keyword, followed by the name of the function, a list of arguments to the function, enclosed in parentheses and separated by commas, the JavaScript statements that define the function, enclosed in curly braces, { }.

JavaScript function has the following syntax:

function name(argument1 , argument2 .... argumentN){
    statement1;
    statement2;
    ..
    ..
    statementN;
} 

Here you can see an example of a JavaScript function:

function greet(name) {
  return "Hello" + name + "!";
}

More information about JavaScript functions you can find via this link. You can also test your JavaScript functions on this site.

More information about PHP functions you can find via this link.

Agregar enlace permanente a marcadores.

Submit a ticket

Si Usted todavía no puede encontrar un tutorial suficiente para arreglar su problema, por favor use el siguiente enlace para enviar un ticket a nuestro equipo de soporte técnico. Nosotros enviaremos nuestra respuesta dentro de próximas 24 horas: Enviar un ticket

Comentarios están cerrados