Skip to content

Commit

Permalink
Merge pull request GitbookIO#61 from sarthakmunshi/patch-2
Browse files Browse the repository at this point in the history
Updated Logical Comparison
  • Loading branch information
AaronO committed Jul 15, 2014
2 parents 1763d84 + ee9ad92 commit 62e4810
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions conditional/comparators.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Other conditional test:
* ```x > a```: is x bigger than a?
* ```x < a```: is x less than a?
* ```x <= a```: is x less than or equal to a?
* ```x >=a```: is x greater than or equal to a?
* ```x != a```: is x not a?
* ```x```: does x exist?

Expand Down Expand Up @@ -44,3 +45,10 @@ assert(a === 10);
```

---
##Logical Comparison
In order to avoid the if-else hassle, simple logical comparisons can be utilised.

```js
var topper = (marks > 85) ? "YES" : "NO";
```
In the above example, `?` is a logical operator. The code says that if the value of marks is greater than 85 i.e. `marks > 85` , then `topper = YES` ; otherwise `topper = NO` . Basically, if the comparison condition proves true, the first argument is accessed and if the comparison condition is false , the second argument is accessed.

0 comments on commit 62e4810

Please sign in to comment.