From 003d0ced09aab1f88f2c428d188a8f212e080ad3 Mon Sep 17 00:00:00 2001 From: Mahnoor Naveed Date: Tue, 26 Oct 2021 08:33:49 +0500 Subject: [PATCH] resolved the ternary operators in javascript --- ternary-operator.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 ternary-operator.js diff --git a/ternary-operator.js b/ternary-operator.js new file mode 100644 index 0000000..885bb71 --- /dev/null +++ b/ternary-operator.js @@ -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 \ No newline at end of file