Tuesday, December 17, 2013

JavaScript Tutorial 3 - Functions

A function is a block of code that will be executed when "someone" calls it. A function is stated by saying function followed by the name of the function for example...

function name () 

The name of this function is called name, now the syntax of a function looks like this...

function myFunction()
{alert("Hello World!");}


myFunction()

Now every time you call that function it will run that block of code this is very useful when you need to write out the same code multiple times.

At this point you are probably wondering why after the function there is "()", well this is where you can add in arguments. Basically this allows you to add in variables to your function  for example...


function myFunction(name,job)
{
alert("Welcome " + name + ", the " + job);}

myFunction(name,job)


This is the basics of Functions and what there syntax is.

No comments:

Post a Comment