Function

Function is a block of statement that performs a specific task and sometime also return a value. using function avoid the need to rewrite the same code again and again.

A function can be called by some other function or it can be called by itself. A function can have none or number of argument or parameters.

Types of function


There are two types of function: Built-in function and user defined function.

User defined function

A user defined function is one that need to be declared and defined by the user. This function can be called by giving its name. These function can accept information in form of argument and can return results.

Declaring function
In JavaScript, a function is declared by using a keyword function.


Three rule for declaring function

  • The name of the function
  • A comma separated list of parameter name in paremtheses: It is optional.
  • A block of statement that forms the body of function.
Syntax of function declaration in JavaScript

 function function-name (parameter 1, parameter 2,…..)
 {
 JavaScript statement;
 }

The function can be declared any where HTML file. However, it is good practice to declare within tag of HTML document.

Leave a Reply