Saturday, 30 March 2013

JavaScript Functions

 
A function doesn't actually do anything until it is called. Once it is called, it takes any arguments, then performs it's function.


Syntax :

function functionname()
{
some code to be executed
}

A function is written as a code block (inside curly { } braces), preceded by the function keyword

Simple example :



Output
<!DOCTYPE html>
<html>
<body>

<p>Click the button to call a function with arguments</p>

<button onclick="myFunction('Steve','M')">Try it</button>

<script>
function myFunction(name,job)
{
alert("Hi  "+ name + "," + "welocme");
}
</script>

</body>
</html>

No comments:

Post a Comment