MCQs Test!! VB Basic Test !! Essentials of VB !! Creating User Services !! function !! Anatomy !! GK March-2019 !! DATA TYPES IN JAVA !! Classes ,Constructor ,Methods,Inheritance !! Ecology-I !! Biology 2019 !! Gk april 2019 !! Biology (living world) !! Plant anatomy !! CELL STRUCTURES AND FUNCTION !! General biology !! Human physiology !! Data structure !! Ecology-II !! GK TEST !! Reproduction in plants !! Human reproduction !! The ABC of C !! Operating system set1 !! Operating system set2 !! Gk and current affairs !! Animal kingdom !! Number system !! Animal kingdom-II !! Gk TEST-III !! Number series !! Microorganisms !! Interview question in c !! Time and Work !! Percentage !! General history !! Average !! Cells !! Locomotion and Movement !! paging !! Bacteriology !! Page replacement policy !! Secondary memory and Disk scheduling !! Introduction of Nervous System and neurons !! Plant harmones !! Transport and Mineral Nutrition in Plants !! Neurotransmitters !! Modern Indian History !! Photosynthesis in Plants !! Modern Indian History-II !! Plant respiration !! Environment & Biodiversity !! Environment & Biodiversity - II !! Algae, Bryophytes, Pteridophytes !! Area !! Cricket !! Days of the Year (India and the World) !! Plant Pathology - I !! Indian Transport System !! Plant Pathology - II !! Aptitude !! Biology !! Botany !! C language !! Computer Science !! Core Java !! Gate !! GK !! Mysql !! Operating system !! Physics !! VB-Visual Basic !! Zoology

JavaScript Tutorial

Statement in JavaScript
Previous Home Next

A statement is the smallest standalone element in programming language which expresses some action to be carried out. A statement may have internal components (e.g., expressions). A program written in such a language is formed by a sequence of one or more statements

JavaScript supports following statement :

  • if statement : use this statement if you want to execute a set of code when a condition is true.
  • if...else statement : use this statement if you want to select one of two sets of lines to execute.
  • if...else if... statement : is the one level advance form of control statement.
  • switch statement : use this statement if you want to select one of many sets of lines to execute.

if statement :

You can use the if statement to check the if a condition is true or false.

Syntax

if (condition)
{
 javascript code to be executed 
}

Example :

<html>
<body>
<script>  
var a=20;  
if(a<5)
{  
document.write("Condition True");  
} 
document.write("Condition False");
</script>  
</body>
</html>

 

Output :

Condition False

if...else statement :

The If else..Statement is a way to make decisions based on a variable or some other type of data. For example, you might have a script that checks if condition or value is true or false,

Syntax

if (condition)
{
   javascript code to be executed if condition is true
}
else
{
   javascript code  to be executed if condition is false
}

Example :

<html>
<body>
<script>  
var a=20;
var b=40;  
if(a<b){  
document.write("true"); 
}  
else{  
document.write("false");  
}  
</script>
</body>
</html>

Output :

true

if...else if... statement :

The if else if... statement is the one level advance form of control statement that allows to make correct decision out of several conditions

Syntax

if (condition1)
{  
javascript code to be executed if condition1 is true  
}  
else if(condition2)

javascript code to be executed if condition2 is true 
 }  
else if(condition3)
{  
javascript code to be executed if condition3 is true 
else{  
javascript code to be executed  if no condition is true  
}  

Example :

<html>
<head> 
<script>  
    var a=20;
    var b=30;  
    if(a<=b)
{  
    document.write("Good morning");  
    }  
    else if(a>=b){ 
    document.write("Good day");  
    }  
    else if (a>=b){  
    document.write("Good night");  
    }  
    else{  
    document.write("Good evening");  
    }  
    </script> 
<head>
<html>

Output :

Good morning

Switch statement :

When we know various or more possibilities comes in a expression then switch statement is an efficient way to do a certain operation on given code

Syntax

switch (expression)
{
case value:
condition;
break;

case value:
condition;
break;

default:
condition;
}

Example :

<html>
<head>
<script>
var day=5;

switch (day)
{
case 0:
document.write ("Today is Sunday");
break;
case 1:
document.write ("Today is Monday");
break;

case 2:
document.write ("Today is Tuesday");
break;

case 3:
document.write ("Today is Wednesday");
break;

case 4:
document.write ("Today is Thursday");
break;

case 5:
document.write ("Today is Friday");
break;

case 6:
document.write ("Today is Saturday");
break;

default:
document.write ("any days");
break;
}
</script>
</head>
</html>

Output :

Today is Friday
Previous Home Next