0% found this document useful (0 votes)
2 views

FunctionDemoTut

Uploaded by

vinothchintam12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

FunctionDemoTut

Uploaded by

vinothchintam12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

<html>

<head>
<script>
add= function()
{
a=100;
b=200;
c=a+b;
alert("Total"+c);
}
function sub(x,y)
{
z=x-y;
alert("Sub"+z);
}
function mul()
{
a=10;b=5;
c=a*b;
return c;
}
function div(x,y)
{
z=x/y;
return z;
}

document.write("1.Add,2:Sub,3.mul,4.div");
ch=parseInt(prompt("Enter ur choice"));
switch(ch)
{
case 1:
add();
break;
case 2:
sub(10,2);
break;
case 3:
rs=mul();
alert("Mul "+rs);
break;
case 4:
rs=div(10,5);
alert("Div"+rs);
break;
default:
alert("Try again");
}
</script>
</head>
<body>
<form>
<input type="button" value="Add" onClick="add()"><br>
<input type="button" value="Sub" onClick="sub(20,10)"><br>
<input type="button" value="Mul" onClick="mul()"><br>
<input type="button" value="Div" onClick="div(30,5)"><br>
</form>
</body>
</html>
*****************************************************************

******************************************************************

<html>
<head>
<script>
fname=undefined;
lname=undefined;
age=0;
getDetails=function(fname,lname,age)
{
this.fname=fname;
this.lname=lname;
this.age=age;
dept="Acc";
}
showDetails=function()
{
document.write(fname+" "+lname+" "+age+" "+dept);
}

/* let show = function() {


console.log('Anonymous function');
};*/

let show = () => console.log('Anonymous function');


let add = (a, b) => a + b;

x=prompt("Enter fname");
y=prompt("Enter lname");
z=prompt("Enter Age");
getDetails(x,y,z);
showDetails();
show();
alert(add(10,5));

</script>
</head>
</html>

**********************************************

<html>
<head>
<script>

let person = {name: 'John', age: 25, idnum:1001, salary:5000 };

function increaseAge(obj) {
obj.age += 1;
}
increaseAge(person);
console.log(person.name+" "+person.age+" "+person.idnum+" "+person.salary);
</script>
</head>
</html>

****************************************************
Lamda (Arrow) functions
Arrow functions
ES6 introduced arrow function expressions that provide a shorthand for declaring
anonymous functions:

For example, this function:

let show = function () {


console.log('Anonymous function');
};
Code language: JavaScript (javascript)
… can be shortened using the following arrow function:

let show = () => console.log('Anonymous function');


Code language: JavaScript (javascript)
Similarly, the following anonymous function:

let add = function (a, b) {


return a + b;
};
Code language: JavaScript (javascript)
… is functionally equivalent to the following arrow function:

let add = (a, b) => a + b;

You might also like