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

125
Views
Conditional Statement in JS is not working in the below code
const myFunction = (props) => {
  let myCondition = false;
  console.log('-----****----',props);

  if(props && props.isAllowed) {
    myCondition = true;
  }
  
  if(someOtherCondition) {
    return(
      <li><Link className="vx_globalNav-links" to="#">Policies</Link>
        <ul>
          <li><Link className="vx_globalNav-links" to="/my-policy">My Policy</Link></li>
          { myCondition && (<li><Link className="vx_globalNav-links" to="/condition-policy">Condition Policy</Link></li>)}
  
        </ul>
      </li>
    );
  }
  return null;
};

The above code seems to be not working for condition based link to display on UI for "Condition policy" even though I get "true" for "myCondition" in the console log which is just logged before the return statement. Wondering What's wrong here. Any help is really appreciated.

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

0

It looks like you put a statement immediately after your if() statement, and so your block of code within { ... } is not executed as part of your if statement.

if(someOtherCondition)
    console.log('', myCondition);
  {
    return(

The curly braces must follow immediately after the if() statement, otherwise, as it is in this case, the console.log is executed when someOtherCondition is true. And whatever is within { ... } is executed anyway regardless.

about 4 years ago · Juan Pablo Isaza Report

0

Your if statement syntax is wrong

about 4 years ago · Juan Pablo Isaza Report

0

Please check the below link, If you are something is not right, then please comment.

https://playcode.io/873851/

  • If you put a condition without { just after the if statement, then the rest of the code does not depend on the condition.
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!