admin管理员组文章数量:1388068
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()){
本文标签: javascripthow to check if function(s) have been executedStack Overflow
版权声明:本文标题:javascript - how to check if function(s) have been executed? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744561153a2612780.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论