-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolved the ternary operators in javascript
- Loading branch information
1 parent
65a2171
commit 003d0ce
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Ternary Operator in Javascript | ||
|
||
// Ternary operators are conditional operators can be use like if and else condition. | ||
// It takes three operands | ||
// 1) condition to check with ? | ||
// 2) an expression to execute if the condition is true with : | ||
// 3) and last expression if the given condition is false | ||
|
||
let a = 5; | ||
let b = 4; | ||
|
||
// USING TERNARY OPERATOR | ||
a > b ? console.log("a is greater than b") : console.log("a and b are not equal"); | ||
|
||
|
||
// USING IF AND ELSE | ||
if (a > b) { | ||
console.log("a is greater than b"); | ||
} else { | ||
console.log("a and b are not equal"); | ||
} | ||
|
||
// OUTPUT | ||
// a is greater than b |