Join TalkersCode Now !

Get Latest Tutorials And Links On Web Development
And Get Existing Offers Via Email

Javascript Functions

Javascript Functions

Functions are the block of code that we want to use again and again simply by calling with their name.


You can make your own functions and use them whenever and wherever you want just simple by making a function and calling that function.

Syntax of Creating a Function

function functionName() 
{
    Your code here;
}

//For calling your function
functionName();

Example of Function

function demo()
{
  alert( "Hello Javascript" );
}
demo();

This will display Hello Javascript.




Syntax of Function with parameters

function functionName(parameters) 
{
    your code here
}

/*For calling your function*/
functionName(parameter);

You can send as many parameters in function as you want.


Example of Function with parameters

function demo(val)
{
  alert( "Here is your value is "+val);
}

demo(10);

This will display Here is your value 10.




Example of Function Return Value

function demo(val)
{
  var add=val+10;
  return add;
}

var val2 = demo(10);
alert( "Here is your value "+val2 );

This will display Here is your value 20.

PreviousNext

Join Us With Our 21000+ Subscribers And Get Our Latest Tutorials Update Via Email

Are You Starting A New Blog
Do You Want Best Web Hosting?

Try World's Best Web Hosting Provider BlueHost
At Just $3.95/mo

Hurry Up! Limited Time Offer

Yes, I Want To Check Out BlueHost

Check The World's Best SEO And All-In-One Marketing Toolkit
For Digital Marketing Professionals SEMRUSH

Check Out SEMRUSH