Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda