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

后端 未结 3 1701
粉色の甜心
粉色の甜心 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:51

    I think a lot of times when you see this code, it's from people who are in the habit of event handlers for forms, buttons, inputs, and things of that sort.

    Basically, when you have something like:

    or

    `
    

    and callSomeFunction() returns true, then the form or a will submit, otherwise it won't.

    Other more obvious general purposes for returning true or false as a result of a function are because they are expected to return a boolean.

提交回复
热议问题