A function is a locked sequence of instructions that allows multiple use with different parameters. A function is a sub-programme. The function is declared in the following way:

  function function_name (parametrs)

The function consists of:
• names,
• a list of arguments called parameters in parentheses ( )
• body, i.e. JS instructions enclosed in braces, { }
• from the "return" command contained in the body of a function, which returns the result of the function


function square(number)
  var w=number*number;
  return w;

The function may not have any parameters, but it must have round brackets:

  function f_name()

The "return" command returns a result if the function generates such a result.


The JS function can be run in html code in at least two ways:
1) automatically, after loading the page through the onLoad event in the <body> section
  <body onLoad = ”f_name()”>
2) by pressing the button or by clicking on the inscription
  <input type = "button" value = "go" onClick = "f_name()">