|
| JAVASCRIPT BOOLEAN OPERATORS
Javascript boolean operators, also known as logical operators allow you to evaluate multiple expressions at a time. Returns either true or false.
These three boolean operators are &&, || and ! and are explained below with examples:
And Operator: &&
Check if both are conditions are satisfied.
Example:
if(firstName=='John' && lastName=='Smith')
{
alert('Welcome');
}
By using && between two conditions, we are saying that only if these two conditions are true, must the code between the braces execute.
Or Operator: ||
Check if either are conditions are satisfied.
Example:
if(firstName=='John' || lastName=='Smith')
{
alert('Welcome');
}
By using || between two conditions, we are saying that if either of these two conditions are true, must the code between the braces execute.
Not Operator: !
Check if conditions are not the case.
Example:
if(!(firstName=='John'))
{
alert('Welcome');
}
We are saying that if firstName is not John, the conditions evaluates to true, then the code between the braces must execute.
 |
|
|