Function

A function is a block of Javascript that does the same thing again and again. It saves repetitive coding and makes your code easier to understand.

Code Structure
Example 1:
function name(fullname) {
 return "Welcome " + fullname + "!";
}
alert(name("Jessica Alba"));

Example 2:
function name(num1, num2) {
 return num1 + num2;
}
alert(name(10,5));

Example 3:
function age(num) {
 if(num < 18){
  alert("You are child.");
 } else {
  alert("You are adult");
 }
}
age(25);

Share this

Related Posts