Skip to content

Commit

Permalink
resolved the ternary operators in javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
mahnoor1999 authored Oct 26, 2021
1 parent 65a2171 commit 003d0ce
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ternary-operator.js
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

0 comments on commit 003d0ce

Please sign in to comment.