functions

by Ananth Arumugasamy

HTML

<button onclick="start()">Click</button>

create a function to display the arithametic operations of 2 values by using return ---> +, - , *, %, /


tmrw----> if, if-else, while, for, for each

CSS

functions
function is a set of code -----> reusuable code
-----> reduce code

define the function:
function  functionname()
{
       set of code;
}

 Function with arguments or parameters
         ----> whenever u pass the value in the functions

return  ----> return the value to caller

x has the value 80
return the c value to sum(5,75) and store it in x.now x has 80

local and global variable:

local variable ---> variable define within the function and we cant access outside the function

calling a another function within a function








&&  or & ---> and
|| or | ---> or

and operator    
T T  T
T F  F
F T  F
F F  F

or operator
T T  T
T F  T
F T  T
F F  F


& | ----> true as 1 and false as 0

JavaScript

function start(a,b)
{
    var x = sum(a,b);
    alert(x);
     
}


start(4,7);

function sum(a,b)
{
    c = a + b;
    return c;  // it will return the value of c to caller
    
}
/*
 function start(a,b)
{
    sum(a,b);
    sub(a,b);
    mul(a,b);
    div(a,b);
}

start(4,5);

function sum(a,b){
    alert(a + b);
}

function sub(a,b){
    alert(a-b);
}

function mul(a,b)
{
    alert(a * b);
}


function div(a,b)
{
    alert(a/b);
}



 function start()    // fn calling inside the function
{
    alert("welcome");
    stop();
    stop1();
    stop2();
}
function stop()
{
    alert("bye Tc");
}
function stop1()
{
    alert("bye janak");
}
function stop2()
{
    alert("all the best");
}

var c = 2;    // global variable

function sum(a,b)
{
    c = 3;  //local variable
    var d = a + b + c;  // gives priority to local variable
    alert(d);
}


sum(4,8);

var c;  // defining global variable
function sum(a,b)
{
    c = 20;    // assign the value inside the function
    var d = a + b + c;
    alert(d);
}

alert(c);



function sum(a,b)
{
    var c = 20;     //local variable
    //var d = a + b + c;
    //alert(d);
    alert(c);
}
//var c = 24;  // global variable
sum(4,5);

function sum(a,b = 30) //default argument
{
    var c = a + b;
    return c;
}

var y = sum(9);
alert(y);


function sum(a,b)
{
    var c = a + b;
    return c;
}

x = sum(5,75);
var d = x + 5;

alert(d);


var x = function(a,b){ c = a + b; alert(c); }  // assign the function to variable. Dont need funcion name. Variable acts as a function name

x(5,5);

function sum(a,b,c=10)
{
    alert(arguments.length);
}
sum(5,6)


function sum(a,b=20) // default arguments    
{
    var c = a + b; 
    alert(c);
}
sum(5,45);  // function calling

function janak()
{
    alert("Hi Janak");
}

janak();*/