I am new to javascript and i am facing a situation here
if (function1() && function2() == true){
//do something here
}
else{
//do something else
}
how do i ensure that function1() and function2() are executed and have true value ?
I am new to javascript and i am facing a situation here
if (function1() && function2() == true){
//do something here
}
else{
//do something else
}
how do i ensure that function1() and function2() are executed and have true value ?
Share Improve this question asked Jul 4, 2017 at 19:21 LeoLeo 771 gold badge1 silver badge11 bronze badges 5-
1
You can drop the
== true
since they both return booleans. – cs95 Commented Jul 4, 2017 at 19:23 -
2
If this condition
if (function1() && function2() ){
is true, it means that these functions was executed and returned true. – davidxxx Commented Jul 4, 2017 at 19:24 - just be aware of that if the first function doesn't return true or the second won't be executed. – NtFreX Commented Jul 4, 2017 at 19:24
-
Should
function2()
be called regardless offunction1()
's return value or only when it returnstrue
? – Marvin Commented Jul 4, 2017 at 19:24 -
function1()
is the return value offunction1
when it is invoked, so isfunction2
when invoked likefunction2()
, what is the problem..? – Redu Commented Jul 4, 2017 at 21:08
1 Answer
Reset to default 4What you have done is correct. Since you using &&
they both execute and when they both return true then only it enters the if
.
As a side note, your code can be shorten to
if (function1() && function2()){