Do I have to return something in javascript function?

后端 未结 3 1209
一个人的身影
一个人的身影 2021-02-18 20:25

In JavaScript functions, do I need to return something (true or false) ? So far, all the functions I wrote without returning anything work just fine. I\'m just curious.

3条回答
  •  长发绾君心
    2021-02-18 21:04

    No you don't

    BUT if you find yourself doing something like this

     function myFun(){
       if (1 == 2){
        return true ;
       }
     }
    

    Now you should know you are doing something wrong in your code because it doesn't make sense that only part of the function return a value

提交回复
热议问题