Functions in Javascript

Function:

A function is a piece of code that sits dormant until it is referenced or called upon to do its “function”. In addition to controllable execution, functions are also a great time saver for doing repetitive tasks.

Instead of having to type out the code every time you want something done, you can simply call the function multiple times to get the same effect. This benefit is also known as “code reusability”.

Example Function in JavaScript:

<html>
<head>
<script type="text/javascript">
<!--
function popup() {
    alert("Hello World")
}
//-->
</script>
</head>
<body>
<input type="button" onclick="popup()" value="click Me">
</body>
</html>