Reputation: 100
A conditional statement is based on concept of if/then/else ; if a condition is met , then your code executes one or more statements , else your code does something different
I encountered this statement and don't understand what "meeting the condition" means.
Upvotes: 0
Views: 3703
Reputation: 1500525
The part in brackets in the if
statement is the condition. For example, in
if (x == 5)
the condition is x == 5
. The condition being "met" basically means "if the expression evaluates to true" (so here, if the value of x
is 5). In Javascript it's a little more complicated than that, because the condition doesn't have to be an actual Boolean expression. Based on the result of the expression, the following evaluation takes place:
If the result of that is true, then the condition is met and the body of the if
statement is executed. Otherwise, the body of the else
part is executed if there is one.
Upvotes: 4
Reputation: 1963
the if instruction is evaluating whatever is inside the parenthesis, if the condition inside the parenthesis is true then the if statemen is executed, otherwise the else statement is executed
var = 5;
if( var === 5)
{
alert("this is shown because var equals 5")
}
else
{
alert("this will never show unless you change var or the condition inside the if parenthesis")
}
Upvotes: 0