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.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
No; Javascript functions are not required to return a value.
If you call a function that doesn't
return
a value, you'll getundefined
as the return value.no you dont. I believe if you do
result will be undefined.
Edit, this screenshot should be illuminating (forgive the mistake when i fail to invoke f):
No you don't
BUT if you find yourself doing something like this
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