JavaScript Functions

JavaScript Functions

Function is a subprogram that allows us to run a group of instructions with a simple call to the function name of one or several parts in the body of a program. Subprogram form we call this function is very commonly used in many programming languages (of course with a slightly different way with each other). On the other way a function, also can call itself, is what we call the function recursively (but do not forget to put a special condition that the function can be stopped, if not endanger the sustainability of global programs).

JavaScript itself has a native function (predefined) which can be applied to one or many kinds of specific objects, we call this function as a method (see chapter 9)

Function Declaration

Before can be used, a function must be defined in advance as to call this function from within the program, the navigator must recognize it first, in the sense to recognize it’s name, it’s argument, and instruction in it. Defining a function is called declaration. The syntax of declaring a function is as follows:

function Function_Name(argument1, argument2, ...) {
list of instructions or blocks of instruction

  • Keyword function followed by the name of the function.
  • Naming of functions have the same rules with naming of variables:
  1. The name must begin by letter.
  2. The name of the function can contain letters, numbers or _ and & characters, empty or space characters are not allowed.
  3. The name of the function as well as a variable name is case sensitive, so pay attention to capital letters and small letters.
  • The argument is optional, may exist or not, if the argument does not exist then the brackets should still be displayed.
JavaScript Functions


Post a Comment