Unit I PPT CSS 4
Unit I PPT CSS 4
1
• Create interactive web pages
CO1 using program flow control
structure
2
TEACHING AND EXAMINATION SCHEME
3
CONTENTS
4
Department of Information Technology,Government
Polytechnic Awasari(kh)
QUERYING AND SETTING PROPERTIES
• The dot (.) operator or square brackets ([]) are used to obtained values of
properties.
for example: var price=book . price; //get the “price” property of the book.
• If using square brackets, the value within the brackets must be an expression that
evaluates to a string that contains the desired property name.
for example: var author= book[“author”] //get the “author” property of the book.
• Use dot or square bracket to create or set a property but place the properties to
the left hand side of an assignment expression.
for example: Book. price=300; // create an “price” property of the book.
person[“first name”]=“john”; //set the “first name “ property
5
Department of Information Technology,Government
Polytechnic Awasari(kh)
DELETING PROPERTIES
• Delete keyword is used to delete both the value of the property and property itself.
for example: delete person-age; // the person object now has no age property
delete person[“FirstName”]; // the person object now has no FirstName property
• The delete property returns true if deleted successfully.
Example:
<html>
<head>
<script language=“javascript” type=“text/javascript”>
Var car={
Color:”red”,
Brand:”ford”
};
document. Write (car. Color +”<br>”+car. Brand +”<br>”);
document. Write(delete car. Brand);
</script>
</head>
</body>
</html>
6
Department of Information Technology,Government
Polytechnic Awasari(kh)
PROPERTY GETTERS AND SETTERS
• Javascript supports are two kinds of properties
1. Data property
2. Accessor properties
• The accessor properties are represented by “getter” and “setter” methods
for the full name property.
• When the property is accessed ,the return value from the getter is used.
get – a function without arguments , that works when a property is
read.
Program: Use of getter method in javascript
<html>
<head>
<script language=“javascript” type=“text/javascript”>
var car ={
color:”red”,
brand:”ford”,
get company() {
return this.brand; }
};
document. Write(“company=“ + car.company);
</script>
</head>
<body>
</body>
</html>
7
Department of Information Technology,Government
Polytechnic Awasari(kh)
PROPERTY SETTERS
• When a value is set , the setter is called and passed the value that was set.
set – a function with one argument , that is called when the property is set.
8
QUIZ TIME
Q1. Which operator are used to Q2. The delete keyword is used for
obtained values of properties?
a) To delete value of property;
a) The dot(.) operator; b) To delete only property itself;
b) Null operator; c) To delete value of property and
c) arithmetic operator; property itself;
d) All of the above; d) To restore the value of property
9
Department of Information Technology,Government
Polytechnic Awasari(kh)
QUIZ TIME
10
Department of Information Technology,Government
Polytechnic Awasari(kh)
THANK YOU
Thank You
11
Polytechnic Awasari(kh)