I am trying to pass any variable is empty and alerting that this variable is empty
var foo ="ss", boo='';
var output;
if(!foo || !boo) {
output = !foo ? !boo + ' is empty';
alert(output);
}
Here if statement works if foo or boo is empty. So if foo is empty alert "foo" else alert "boo"
var foo ="ss", boo='';
if(!foo || !boo) {
alert(!foo ? 'foo is empty' : "boo is empty");
}
const foo = "ss",
boo = '';
const output = `${!foo && "foo" || !boo && "boo"} is empty`;
alert(output);
You are using the ternary IF operator but are missing the third (last) argument. The syntax goes CONDITION ? IF_TRUE_VALUE : ELSE_VALUE. Check the implementation below.
var foo = "ss", boo = '';
var output;
if (!foo || !boo) {
// if foo is empty then display foo or else boo
output = (!foo ? 'foo' : 'boo') + ' is empty';
alert(output);
}