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

162
Views
Why doesn't true return when an empty string is included in the conditional statement?

I wrote an if statement using the following data.

const data = {
  field: ""
}

const data2 = {
  field: "abc"
}

if (data.field && data.field !== data2.field) {
  console.log('not in')
}

I was expecting that if condition to return true, but it returns an empty string("") so it is not included in the branch.

As shown below, if it is not an empty string(""), true is returned. Why isn't true if an empty string("") is included in the conditional statement?

const data = {
  field: "ccc"
}

const data2 = {
  field: "abc"
}

if (data.field && data.field !== data2.field) {
  console.log('in')
}
about 4 years ago · Juan Pablo Isaza
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!