JavaScript Function Syntax

A JavaScript function is defined with:

  1. The keyword: function
  2. A name -- function names can contain letters, digits, underscores, and dollar signs (same rules as variables).
  3. Parentheses () -- which may include parameter names separated by commas: (parameter1,  parameter2, ...).
  4. Then curly brackets {}, which contain the code to be executed by the function.

   function name(parameter1, parameter2, parameter3) {
     code to be executed
   }

A Function is much the same as a Procedure or a Subroutine, in other programming languages.

Back Table of Contents Next