Functions in Javascript


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:

<script type="text/javascript">
function popup() {
    alert("Hello World")
<input type="button" onclick="popup()" value="click Me">

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s