Do I have to return something in javascript function?

后端 未结 3 1200
一个人的身影
一个人的身影 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:00

    no you dont. I believe if you do

    var result = iAmADefinedFunctionThatDoesntReturnAnything();
    

    result will be undefined.

    Edit, this screenshot should be illuminating (forgive the mistake when i fail to invoke f):

    enter image description here

提交回复
热议问题