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

243
Views
If statement is returning both true and false statment in javascript

The function is accepting (val) as an argument and if the (val == 5) it should execute if statement and return Equal, otherwise not equal. But if val is equal to 5 then also function is returning false Not Equal. Beginner Here. Thanks

javascript

 function testNotEqual(val) {
    if (val == 5) { 
      return  "Equal";
    }

    else {
      return "Not Equal";
 
    }

    
    
  }
 
  testNotEqual(5);
  console.log(testNotEqual());

enter image description here

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

0

Try this:

  function testNotEqual(val) {
    if (val == 5) { 
      return  "Equal";
    }

    return "Not Equal";
    
  }
 
  let test = testNotEqual(5);
  console.log(test);
about 4 years ago · Juan Pablo Isaza Report

0

You invoked this function twice and second time you passed nothing as an argument

function testNotEqual(val) {
    if (val === 5) {
      return "Equal";
    } else {
      return "Not Equal";
    }
  }
 
  
  document.getElementById("te").innerHTML = testNotEqual(5);
body {
    margin: 0;
    background: #333;
}
<p style="color:white" >The Result is: <span id="te"></span>
    </p>

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!