Answers for "convert normal if condition to ternary operator"

15

javascript ternary operator

//ternary operator syntax and usage:
condition ? doThisIfTrue : doThisIfFalse

//Simple example:
let num1 = 1;
let num2 = 2;
num1 < num2 ? console.log("True") : console.log("False");
// => "True"

//Reverse it with greater than ( > ):
num1 > num2 ? console.log("True") : console.log("False");
// => "False"
Posted by: Guest on February-02-2020
18

javascript ternary operator

//ternary operator example:
var isOpen = true; //try changing isOpen to false
var welcomeMessage  = isOpen ? "We are open, come on in." : "Sorry, we are closed.";
Posted by: Guest on August-05-2019
0

convert normal if condition to ternary operator

const age = 19;
if(age >= 18) {
   const canVote = true;
} else {
   const canVote = false;
}

if (age>18) {
  console.log("Mozete glasati")
}
Posted by: Guest on May-24-2021

Code answers related to "convert normal if condition to ternary operator"

Code answers related to "Javascript"

Browse Popular Code Answers by Language