A function is a block of code that performs some action. The statements written in the function are executed when it is called by its name. We write functions because a program may need to repeat the same piece of code at various places.
<script type="text/javascript">
alert('Hello World !');
</script>
Those functions that user define to solve particular problem are the user defined functions.A user defined functions consists of following. 1- Function declaration. 2- Function Definition or block of statements.
function function_name()
{
statement;
}
<script type="text/javascript">
function WelcomeFunction()
{
alert("Welcome to Coding JavaScript Tutorial Series");
}
</script>
JavaScript function can be called by different methods , we will discuss few methods here.
<button onclick='WelcomeFunction()'>Click me </button>
<a href="javascript:WelcomeFunction">Click me</a>
<html>
<head>
<title> Java Script Functions </title>
</head>
<body>
<script type="text/javascript">
function WelcomeFunction()
{
alert("Welcome to Coding JavaScript Tutorial Series");
}
</script>
<a href="javascript:WelcomeFunction()">Click me</a>
</body>
</html>