Conditional statements:
JavaScript conditional statements allow you to execute specific blocks of code based on conditions. If the condition is met, a particular block of code will run; otherwise, another block of code will execute based on the condition.
Let see if statement:
The if statement:
The if statement evaluates a condition inside parentheses. If the condition is true, the block of code inside the curly braces {} runs. If it’s false, it skips that block.
let mark = 36;
let result;
if(mark >= 35)
{
result = "pass"
}
else{
result = "fail"
}
The if else statement:
The if-else statement will perform some action for a specific condition. Here we are using the else statement in which the else statement is written after the if statement and it has no condition in their code block.
if (ind>pak){
console.log("ind win")
}else if ( pak > ind){
console.log("pak won")
} else{
console.log("draw")
}
Nested if else statement:
A nested if...else statement is an if...else structure placed inside another if or else block. This allows you to check multiple conditions in a hierarchical or layered way, making complex decision trees possible.
if (budget <= 25000)
{
if (budget == "samsung")
{
if(cam == "64mp")
else{
(cam == "48mp")
}
}
else if{
if (brand == "oppo") {
if (cam == "72mp") {
}
}
And what about the
switch
?