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

123
Views
Statement for specific truth table

I have three variables, variation, attribute and active for which I need to create an if statement for the following truth table:

variation attribute active Result
[object Object] 'color' true TRUE
undefined undefined undefined TRUE
[object Object] 'color' false FALSE

But I can't think of a smart and compact statement for the case, unless I write all desired true scenarios in an or separated long statement...

Can someone please help me with this?

Here is a quick fiddle for you.

TIA.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can negate all the values to booleans and check if they are all equal:

!variation == !attribute && !attribute == !active

Values in JavaScript can be either truthy or falsy.

  • [object Object], 'color', true => truthy
  • undefined, false => falsy

So when you put the logical NOT operator (!) before a value, you effectively negate it, meaning all truthy values become the boolean false and all falsy values are cast to the boolean true.


Your truth table seems to return true when all of the variables are truthy or when all of the variables are falsy, and returns false when they are mixed.

So it essentially checks that all the values, when casted to booleans, are equal. So the condition above casts the values to opposite booleans and checks that they are all the same.

about 4 years ago · Juan Pablo Isaza 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!