OUTLINE
• If Statement
• Switch case Statement
• Loop Statement
• Querying and setting properties
• Property getters and setters
IF STATEMENTS
If Statement
If else Statement
IF STATEMENTS
If else---if Statement
if(conditional expression1)
{
//code1
}
else if(conditional expression2)
{
//code2
}
else if(conditional expression3)
{
//code3
}
else
{
//code 4
}
IF STATEMENTS
Nested If else
if(conditional expression1)
{
//code1
if(conditional expression2)
{
//code2
}
else
{
//code3
}
}
else
{
}
SWITCH CASE STATEMENT
LOOP STATEMENT
Java script supports following loop statements
• for loop
• for in
• while loop
• do while loop
• Syntax of for in
for (key in object)
{
//code block
}
QUERYING AND SETTING PROPERTIES
• To obtain value of property dot (.) or square bracket operators are
used
• Syntax
Object_name.Property_name
OR
Object_name[“Property_name”]
• For example
let studobj = {Name:"Jhon",Rollno:1104,Marks:92.78};
nm = studobj.Name;
mk = studobj["Marks"];
studobj["Marks"] = 87.23;
QUERYING AND SETTING PROPERTIES
Adding and deleting object properties
• New property can be added using following syntax:
Object_name.New_Property_name = Value;
OR
Object_name[“Property_name”] = Value;
• Property can be deleted by using following syntax:
delete Object_name.Property_name ;
OR
delete Object_name [“Property_name”] ;
PROPERTY GETTERS AND SETTERS
• There are two types of object properties –
• The first kind is data properties (which we have been using until
now)
• Second type of property is an accessor property
• Accessor properties are essentially functions that execute on
getting and setting a value, but look like regular properties to an
external code