Conditional Statement |
Syntax |
Example |
Output |
If |
if (condition) { Code } |
if (3>2) { document.write("3 is big"); } |
3 is big |
Else |
if (condition) { code } else { code }
|
if (2>3)
{ document.write("2 is big"); }
else { document.write("3 is big"); }
|
3 is big |
Else if |
if (condition1)
{ code }
else if (condition2)
{ code }
else {code }
|
if (2>3)
{ document.write("2 is big"); }
else if (3>2) { document.write("3 is big"); }
else {document.write("Both are same"); }
|
3 is big |
switch |
switch(2)
{
case 1: code block; break;
case 1: code block; break;
default: code block; break;
}
|
switch(expression)
{
case 1: document.write("Selected Case2"); }; break;
case 2: document.write("Selected Case2"); }; break;
default:document.write("Selected Case Default"); }; break;
}
|
Selected Case2 |