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

220
Views
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 answers
Answer question

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 Report

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 Report

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 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!