Following are some conditions used in JavaScript
if condition will execute a block of code.., if is used when statement is whether true or false.
else condition used when a block of statement is false
else if condition used to check more & more statements whether they are true
switch to specify many alternative blocks of code to be executed
If condition
if (condition) {
block of code to be executed if the condition is true}
if should be in lower case... if is in uppercase then JavaScript will show error.
<p id="demo"></p>
<script>
if (5 == 5) {
document.getElementById("demo").innerHTML = "True";
}
</script>
Output : True
Else Condition
<p id="demo"></p>
<script>
if (5 == 7) {
document.getElementById("demo").innerHTML = "True";
}else {
document.getElementById("demo").innerHTML = "False";
}
</script>
Output: False
Else if Statement
if (condition1) {
statement
statement
} else if (condition2) {
statement
statement
} else {
statement
statement
}
Switch Statement
switch(expression) {
case n:
code
break;
case n:
code
break;
default:
code
}
Break Keyword : When execution reached Break keyword the program will run out of Switch statement. If we don't use Break all codes will be read by device.
No comments:
Post a Comment