The most common way to define a function in JavaScript is by using the 'function' keyword, followed by a unique function name, a list of parameters (that might be empty), and a statement block surrounded by curly braces.
Here is an example of a simple function. NOTE: Nothing happens until you call or invoke it!!!
<script type = "text/javascript">
function sayHello() {
alert("Hello there");
}
</script>
Click the following button to call the function
This is the code to call the function:
<input type = "button" onclick = "sayHello()" value = "Say Hello">
The biggest mistake a beginner makes is to write a function and forget to call the function. A function doesnt work until you invoke or call it.