javascript return true or return false when and how to use it?

后端 未结 3 1699
粉色の甜心
粉色の甜心 2020-12-23 14:31

So I see a lot of JavaScript code (have written some myself) that does something like



        
3条回答
  •  北海茫月
    2020-12-23 14:53

    returning true or false indicates that whether execution should continue or stop right there. So just an example

    
    

    Now if func() is defined like this

    function func()
    {
     // do something
    return false;
    }
    

    the click event will never get executed. On the contrary if return true is written then the click event will always be executed.

提交回复
热议问题