DEV Community

seopoint35
seopoint35

Posted on

what is the diffrence between these if else condition

React js
when we fill the value in first input is condition ok
if(values.fname.length < 3 && values.lname.length < 3 ){
btnAction = true;
}else{
btnAction = false;

}

this condition work proper
if(values.fname.length < 3 ){

btnAction = true

}else if(values.lname.length < 3 ){
btnAction = true;
}else{
btnAction = false;
}

Top comments (1)

Collapse
 
gregorywitek profile image
Gregory Witek

The 2nd condition is equivalent of "or", you can write it like this:

if(values.fname.length < 3 || values.lname.length < 3 ) {
  btnAction = true;
} else {
  btnAction = false;
}

Also, because the expression values.fname.length < 3 || values.lname.length < 3 already returns true or false, you can rewrite this code like this:

btnAction = values.fname.length < 3 || values.lname.length < 3