Videogamer555 Posted September 6, 2014 Share Posted September 6, 2014 (edited) What if I want to create a function without a returned value (something that is self contained, rather than generating a value for use in other JScript code)? For example if I have "document.write('test.')" as my the code for my function, its output will be writing this text directly to the browser window. Do I need to have a Return statement just to make it "officially correct"? Or can I leave out the Return statement when the function does not return a value? Currently my code is: <html><head><title>index</title><script type="text/javascript">function testfunc() {document.open();document.write('test');document.close();}</script></head><body>This is <span onclick="testfunc();">a</span> test.</body></html> I need to know if I need a "return;" after my "document.close();". Edited September 6, 2014 by Videogamer555 Link to comment Share on other sites More sharing options...
JamesB Posted September 6, 2014 Share Posted September 6, 2014 Functions don't have to return a value. Link to comment Share on other sites More sharing options...
Videogamer555 Posted September 6, 2014 Author Share Posted September 6, 2014 (edited) Functions don't have to return a value. If they do not return a value, do they still need a "return" statement to be officially correct? For example: function MyFunc(){some code that does somethingreturn true;} Is this required by the JavaScript standard, or not? Edited September 6, 2014 by Videogamer555 Link to comment Share on other sites More sharing options...
Ingolme Posted September 6, 2014 Share Posted September 6, 2014 A return statement is not required. Link to comment Share on other sites More sharing options...
davej Posted September 6, 2014 Share Posted September 6, 2014 In Javascript the return statement is only used if you want to have a returned value. In some cases a boolean value of 'false' is returned by an event handler in order to disable a default action. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now