最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to check if function(s) have been executed? - Stack Overflow

programmeradmin2浏览0评论

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 of function1()'s return value or only when it returns true? – Marvin Commented Jul 4, 2017 at 19:24
  • function1() is the return value of function1 when it is invoked, so is function2 when invoked like function2(), what is the problem..? – Redu Commented Jul 4, 2017 at 21:08
Add a ment  | 

1 Answer 1

Reset to default 4

What 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()){
发布评论

评论列表(0)

  1. 暂无评论