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

221
Vistas
Expecting a Bool, Getting null

I have a function in a class

MyClass.prototype.IsFriend = function(){
    return (this.m_Object1 && !this.m_Object1.m_ABoolean && this.m_Object2);
};

m_Object1 is an object in MyClass.

m_ABoolean is a boolean within m_Object1, true or false.

m_Object2 is another object in MyClass.

When this function should be returning false when m_Object1 is null OR m_ABoolean is true OR m_Object2 is null, it returns null instead.

Note: m_Object1, m_ABoolean and m_Object2 are never undefined.

Why?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

The && operator return the first falsy value (the operand itself) it encounters, if it encounters null it will return null -> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND

about 4 years ago · Juan Pablo Isaza Denunciar

0

Logical operators in javascript return the first logically determined value from left to right,
For instance, && operator returns the first value if it's falsy or the second one if not.

This answer is a good read and the MDN Documentation is a good reference.

about 4 years ago · Juan Pablo Isaza Denunciar

0

I think that some of your values are null since:

true && null === null

Don't you have a way to check with debugger or with console.log the output of these values?

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