in java script a function is declared with keyword function followed by parentheses .Function may contain a parameter . The code of function executes when function is being called.
In JS function may be declared as following. In following example the function is being called on onLoad event . So it executes when we open the web page.