Friday, July 25, 2014

Javascript Functions

-Why functions?

  • its a block of code which execute when something call it 

-What the benfits of useing functions?

  • if we want to find the max between 10 numbers we should make the comparison 10 times by writing 

  • instead of writing a code more than one time we can write a function and then call it any time we want so for the previous example we can call the function anytime we want to get the max number 
-Functions syntax:

  • to define a function we should start with "function" keyword then the name of the function then "()" and the blocks braces "{}"
  • name of the functions can include :letters,digits,signs,underscore BUT it can have a space 


-Functions parameters:

  • since we want to call our functions and use it to do a special task we'll want to get some data from other parts of the code but how can we use them in our function its simply by passing them through parameters lets see this example:

-Function Return Statements:
  • after calling our functions and after getting the code executed where the value of that function will go it'll be usefulness if the function called and then finished without getting data from it thats why we should use the Return statements
          what do Return do?
  • first of all since just like every programming language the compiler "which execute the code and change it from data to inforamtions" it reads line by line so when it reach the "return" statemnts it stop compling and the return value will return to the caller of that function :


  • now x have the value of x+y which is 13
-Functions and objects:
  • you should know that functions are objects because they have their own properties and methods

------------------------------------------------The End----------------------------------------------------

--------------------------------------------hope you like it-------------------------------------------------

No comments:

Post a Comment