Professional Documents
Culture Documents
S09 MSWD Class
S09 MSWD Class
function FC()
{
return <h1>Function Component Demo</h1>
}
-- Program
-- Program
<html>
<head>
<title>JavaScript named and anonymous function example</title>
</head>
<body>
<script>
// Named function
function nameShowMessage() {
let x;
x = 'JavaScript by Shagufta!'
console.log(x);
return x;
}
// Anonymous function
const anonyShowMessage = function () {
let y;
y = 'JavaScript by Shagufta!'
console.log(y);
return y;
}
nameShowMessage();// Named function
anonyShowMessage();// Anonymous function
</script>
</body>
</html>
>> Arrow functions are a new way to write anonymous function expressions in
JavaScript
-- Program
-- Program
alert( sum(1, 2) ); // 3
-- Program
>>JS OOPS
<script>
//Declaring class
class Employee
{
//Initializing an object
constructor(id,name)
{
this.id=id;
this.name=name;
}
//Declaring method
detail()
{
document.writeln(this.id+" "+this.name+"<br>")
}
}
//passing object to a variable
var e1=new Employee(101,"Martin Roy");
var e2=new Employee(102,"Duke William");
e1.detail(); //calling method
e2.detail();
</script>
<html>
<head>
<script type="text/javascript">
var employee={first:"John", last:"Doe", department:"Accounts"};
var details = "";
document.write("<b>Using for/in loops </b><br />");
for (var x in employee)
{
details = x + ": " + employee[x];
document.write(details + "<br />");
}
</script>
</head>
<body>
</body>
</html>
<script>
var emp=new Object();
emp.id=101;
emp.name="Ravi Malik";
emp.salary=50000;
document.write(emp.id+" "+emp.name+" "+emp.salary);
</script>
<script>
function emp(id,name,salary){
this.id=id;
this.name=name;
this.salary=salary;
}
e=new emp(103,"Vimal Jaiswal",30000);