JavaScript Ternary operators
First we have to discuss if{}else{}
Statement.
num=4;
msg="";
if(num%2==0){
msg="even";
}else{
msg=odd
};
console.log(msg);
//even;
Now it's rewrite in ternary way;
num=4;
msg=num%2==0?"even":"odd";
console.log(msg)
//even
it's shorter code;
prudhvi.hashnode.dev1 min read