Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
check and pass the variable is empty in javascript

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);
}
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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");

}

about 4 years ago · Santiago Trujillo Report

0

const foo = "ss",
  boo = '';
const output = `${!foo && "foo" || !boo && "boo"} is empty`;
alert(output);

about 4 years ago · Santiago Trujillo Report

0

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);
}

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!